# Elasticsearch slow query response time using terms facet

**URL:** https://discuss.elastic.co/t/elasticsearch-slow-query-response-time-using-terms-facet/14549
**Category:** Elasticsearch
**Created:** [November 22, 2013, 6:20pm UTC](https://discuss.elastic.co/t/elasticsearch-slow-query-response-time-using-terms-facet/14549 "2013-11-22T18:20:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vinamar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vinamar](https://discuss.elastic.co/u/vinamar)
#### Post date: [November 22, 2013, 6:20pm UTC](https://discuss.elastic.co/t/elasticsearch-slow-query-response-time-using-terms-facet/14549/1 "2013-11-22T18:20:25Z")

</div>

We are experiencing unusual slow query response time using terms facets.  
With faceted search, the query takes around 15 to 20 secs to return the response.  
Without faceted search the query takes around 2 secs (still on the higher order of latency)  
Earlier With 11m documents and 3 data nodes and 2 non data nodes, the latency would be in the order of 100 to 200ms. Not sure whats going on here.

Couple of observations:  
a) The shards are not equally/fairly distributed among the 10 data nodes  
b) The master could be a data node or a non data node  
c) I thought adding more nodes would result in faster search response time (but i'm seeing decrease in performance of query execution) ?

Specs:  
Elasticsearch v0.90.2  
25 Million text documents indexed  
10 Data nodes (running on Centos 6)  
2 Non data nodes (running on Centos 6)  
running on JVM 7

Query issued:  
GET \_search  
{  
"facets": {  
"histo": {  
"date\_histogram": {  
"field": "closeDt",  
"interval": "1.5h"  
}  
},  
"channel": {  
"terms": {  
"field": "channel"  
}  
},  
"siteId": {  
"terms": {  
"field": "siteId"  
}  
}  
},  
"query": {  
"filtered": {  
"filter": [  
{  
"range": {  
"closeDt": {  
"from": 1325404800000,  
"to": 1385107200000  
}  
}  
}  
],  
"query": {  
"query\_string": {  
"query": "ebay now",  
"default\_operator": "AND",  
"fields": [  
[  
"emails.emailBody",  
"srId",  
"chatTextArray.text"  
]  
]  
}  
}  
}  
},  
"highlight": {  
"pre\_tags": [  
""  
],  
"post\_tags": [  
""  
],  
"fields": {  
"srId": {  
"number\_of\_fragments": 0  
},  
"emails.emailBody": {  
"number\_of\_fragments": 0  
},  
"chatTextArray.text": {  
"number\_of\_fragments": 0  
}  
}  
},  
"timeout": 30000  
}

Query response:  
{  
 **"took": 24426,**  
"timed\_out": false,  
"\_shards": {  
"total": 16,  
"successful": 10,  
"failed": 6,  
"failures": [  
{  
"index": "\_river",  
"shard": 0,  
"status": 400,

Without facets - query response time is 2 secs (still the latency is high)  
{  
"took": 2625,  
"timed\_out": false,  
"\_shards": {  
"total": 16,  
"successful": 16,  
"failed": 0  
},  
"hits": {  
"total": 3942856,  
"max\_score": 0.30295128,  
"hits": [

Cluster health:  
{  
cluster\_name: elasticsearch\_dc1  
status: yellow  
timed\_out: false  
number\_of\_nodes: 12  
number\_of\_data\_nodes: 10  
active\_primary\_shards: 16  
active\_shards: 31  
relocating\_shards: 0  
initializing\_shards: 1  
unassigned\_shards: 0  
}

---

<div class="post-metadata">

### Author: ![vinamar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vinamar](https://discuss.elastic.co/u/vinamar)
#### Post date: [December 2, 2013, 8:20pm UTC](https://discuss.elastic.co/t/elasticsearch-slow-query-response-time-using-terms-facet/14549/2 "2013-12-02T20:20:51Z")

</div>

We tried using \_optimize to merge segments to 1 per shard, it helped quite a bit.

Still our query response time is \> 1 sec.

Total number of documents indexed: 25,127,713  
Query: ebay

# of hits: 18,527,606 results

Time taken: 5.54 seconds (wow !)

# of indexes searched : 2

there is one shard per index and each shard is of size 20gb

---

<div class="post-metadata">

### Author: ![vinamar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vinamar](https://discuss.elastic.co/u/vinamar)
#### Post date: [December 2, 2013, 10:42pm UTC](https://discuss.elastic.co/t/elasticsearch-slow-query-response-time-using-terms-facet/14549/3 "2013-12-02T22:42:55Z")

</div>

Query issued:  
GET \_search  
{  
"query": {  
"filtered": {

```
     "query": {
        "query_string": {
           "query": "ebay",
           "default_operator": "OR",
           "fields": [
              [
                 "emails.emailBody",                    
                 "chatTextArray.text"
              ]
           ]
        }
     }
  }

```

}  
}

Response:  
{  
"took": 2989,  
"timed\_out": false,  
"\_shards": {  
"total": 10,  
"successful": 10,  
"failed": 0  
},  
"hits": {  
"total": 18527794,  
"max\_score": 0.094853,  
"hits": [  
{  
"\_index": "email2",  
"\_type": "json",  
"\_id": "1288731070",  
"\_score": 0.094853,  
"\_source": { ..}  
} ]  
}

Default query:  
GET \_search?  
{  
"query": {  
"filtered": {  
"filter": [  
{  
"range": {  
"closeDt": {  
"from": 1325404800000,  
"to": 1386057600000  
}  
}  
}  
]  
}  
}  
}

Response:  
{"took":1815,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":22035134,"max\_score":1.0,"hits":[{"\_index":"email2","\_type":"json","\_id":"1273442109","\_score":1.0, "\_source" : {..}

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 2:03am UTC](https://discuss.elastic.co/t/elasticsearch-slow-query-response-time-using-terms-facet/14549/4 "2017-07-06T02:03:45Z")

</div>


