Hi,
I came across this article from ES on indexing fields as keywords would result in faster in search performance than having them as numerics
I went ahead and benchmarked this and found out that this was not the case. Hence I'm posting here to see if there is anything wrong with my benchmarking methodology.
Current mappings :
"abc": {
"properties": {
"id": {
"type": "long"
}
}
}
Changing this to
"abc": {
"properties": {
"id": {
"type": "keyword",
"fields": {
"sort_order": {
"type": "long"
}
}
}
The plan was to use abc.id for search and abc.id.sort_order for aggregations.
Details of my experiment :
I have my own script that creates randomly generated terms search for the field abc like,
the ids generated for abc field search is randomly generated numbers from 1 to 30 in every search query
{
"query": {
"size": 50,
"bool": {
"filter": [
{
"terms": {
"abc.id": [44,5]
}
},
{
"terms": {
"account_id": [7, 17, 20]
}
}
]
}
},
"sort": [
{
"nice_id": "asc"
}
]
}
Each index (old schema and new schema) consisted about 78M docs.
About the experiment
- We ran ingestion in parallel into the index, to rule out stale data issue.
- We ran multiple iterations of queries each making 20k in one run with and without sort, to average out any one-off’s
- Cleared the cache of the index before every new iteration using the cache clear API
- Scoped the queries to 3 accounts and ran 20K queries in each iteration.
- Every search query had randomly generated abc.id to achieve a wider range of queries
- Requested result size of 50 in every query
- Ran in the order: With Sort, Search only, Search only, With Sort, With Sort, Search only
The results :
On an average :
Searching over long : 58.48 ms
Searching over keyword : 65.28 ms
Search & Sort on long : 41.67 ms
Search on long & sort on keyword : 53.71 ms
We found out that search on long is actually faster than keywords (this goes against what ES recommended)
I wanted to know :
- Why would search perform faster on long than keyword?
- Why would search and sort be faster than just search ?
- Is there a better way to benchmark these scenarios and if there is something that I'm doing wrong here?
Let me know if you need more details on anything.