Performance of Term Query vs Terms Query with 1 value

(Mohit Kathuria) #1

We have an Elasticsearch cluster setup of 5 data nodes, 3 master with version 5.2.2. The cluster has 10 indices, namely txn_0, txn_1 ... txn_9 where Ith index has all transactions of a user with modulus of 10 as I. For example: All data of user Id 101 will be in index txn_1. Also, we are using shard routing to further optimise the routing of data to a particular shard.

Our query pattern includes search on data for a particular user. Recently, we were trying to optimise our query latency and we figured out that performance of terms query with single value was worse than the performance of term query. Be default, all our queries were terms query and when we changed to term, we saw massive improvement in query latency. We were not still quite sure of this behaviour after research, hence I am writing to the community to decipher this behaviour.

In this respect, I understand that term queries are not cached by default and terms query are (depending on frequency of queries & segment size).

Below is our query:
Old Query -
New Query -

The only change in query was to change a particular terms query to term. This particular field txnType is low cardinality field with cardinality of around 100, but each value of txnType will have few millions to 1 billion hits each.

(Mohit Kathuria) #2

Anyone else also seeing similar behaviour?

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.