# Performance Question

**URL:** <https://discuss.elastic.co/t/performance-question/91837>\
**Category:** Elasticsearch\
**Created:** [July 5, 2017, 5:17am UTC](https://discuss.elastic.co/t/performance-question/91837 "2017-07-05T05:17:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ytzlax](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ytzlax/32/34754_2.png) [@ytzlax](https://discuss.elastic.co/u/ytzlax)\
**Post date:** [July 5, 2017, 5:17am UTC](https://discuss.elastic.co/t/performance-question/91837/1 "2017-07-05T05:17:05Z")

</div>

I want to execute elasticsearch request and I have a doubt what the best way to do that.  
The first option is with msearch request, each search with the same filter query but with different aggregation.  
The second option is with one search request , and multiple, aggregations.

My question is with option is more faster?

**Option 1:**

```
   GET myindex/_msearch
{}
{"size":0,"query":{"bool":{"must":[],"must_not":[{"match":{"field1.keyword":{"query":"aab"}}}]}},"aggs":{"attrBucket":{"terms":{"field":"field1.keyword"}}}}
{}
{"size":0,"query":{"bool":{"must":[],"must_not":[{"match":{"field1.keyword":{"query":"aab"}}}]}},"aggs":{"attrBucket":{"terms":{"field":"field2.keyword"}}}}
{}
{"size":0,"query":{"bool":{"must":[],"must_not":[{"match":{"field1.keyword":{"query":"aab"}}}]}},"aggs":{"attrBucket":{"terms":{"field":"field3.keyword"}}}}   

```

**Option 2:**

```
GET myindex/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [],
      "must_not": [
        {
          "match": {
            "field1.keyword": {
              "query": "aab"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "attrBucket1": {
      "terms": {
        "field": "field1.keyword"
      }
    },
    "attrBucket2": {
      "terms": {
        "field": "field2.keyword"
      }
    },
    "attrBucket3": {
      "terms": {
        "field": "field3.keyword"
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 5, 2017, 2:05pm UTC](https://discuss.elastic.co/t/performance-question/91837/2 "2017-07-05T14:05:56Z")

</div>

It is tricky, the first request will be able to use your cluster more, meaning it might help with latency but hurt throughput. The second request theoretically is better since it only computes the set of matching documents once, but I can't guarantee it will be better in practice.

By default, I'd go with the second option, especially if you expect a high concurrent query load.

---

<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:** [August 2, 2017, 2:06pm UTC](https://discuss.elastic.co/t/performance-question/91837/3 "2017-08-02T14:06:20Z")

</div>

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