Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P913
random es_search with word typing simulation
Active
Public
Actions
Authored by
vsellier
on Jan 4 2021, 9:40 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
Archive search
Subscribers
None
#!/bin/bash -eu
searched
=
1
total
=
5
RANDOM_WORD
=
"
$(
sort -R /usr/share/dict/words
|
head -
${
total
}
)
"
WORD
=
"
${
1
:-
$RANDOM_WORD
}
"
export
ES_SERVER
=
192
.168.100.81:9200
for
w in
$WORD
;
do
echo
echo
"Searching for
$searched
/
$total
$w
"
letters
=
"
$(
grep -o
'.'
<<<
$w
)
"
search
=
""
search_file
=
$(
mktemp
)
result_file
=
$(
mktemp
)
for
l in
$letters
;
do
search
=
"
$search$l
"
cat
<<EOF >"${search_file}"
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "${search}",
"type": "bool_prefix",
"operator": "and",
"fields": [
"url.as_you_type",
"url.as_you_type._2gram",
"url.as_you_type._3gram"
]
}
}
]
}
},
"sort": [
{
"_score": "desc"
},
{
"sha1": "asc"
}
]
}
EOF
curl -s -XGET -H
"Content-Type: application/json"
http://
${
ES_SERVER
}
/origin/_search
\?
pretty -d @
"
$search_file
"
>
"
${
result_file
}
"
took
=
"
$(
jq
'.took'
$result_file
)
"
results
=
"
$(
jq
'.hits.total.value'
$result_file
)
"
echo
"Searching for
$search
: took=
${
took
}
ms nb_results=
${
results
}
"
done
searched
=
$((
searched
+
1
))
done
# echo
# echo "Search took $()ms"
# echo "Number of results: $()"
# echo
#jq '.hits.hits[]._source.url' $result_file
rm
$search_file
$result_file
Event Timeline
vsellier
created this paste.
Jan 4 2021, 9:40 AM
2021-01-04 09:40:43 (UTC+1)
vsellier
mentioned this in
T2905: Deploy swh-search for production
.
Log In to Comment