# Bool Query with multiple term queries inside should OR MultiSearch Queries

**URL:** <https://discuss.elastic.co/t/bool-query-with-multiple-term-queries-inside-should-or-multisearch-queries/113385>\
**Category:** Elasticsearch\
**Created:** [December 28, 2017, 5:24am UTC](https://discuss.elastic.co/t/bool-query-with-multiple-term-queries-inside-should-or-multisearch-queries/113385 "2017-12-28T05:24:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [December 28, 2017, 5:24am UTC](https://discuss.elastic.co/t/bool-query-with-multiple-term-queries-inside-should-or-multisearch-queries/113385/1 "2017-12-28T05:24:01Z")

</div>

I have bool query which is perfectly satisfying my request which is like:

```
GET product/product/_search?pretty
{
  "query" : {
    "bool": {
      "should": [
        {
          "term": {
            "field1" : "xxxx1"
          }
        },
        {
          "term" : {
            "field2" : "xxxx2"
          }
        },
        {
          "term" : {
            "field1" : "xxxx3"
          }
        }
      ]
    }
  }
}

```

I am thinking whether this will be faster or multisearch request like shown below.  
But in multisearch request I need coagulate all responses if there responses with same document in it.  
But in above, for e.g. I am getting 2 documents. This is what I require.  
In case of multisearch, I will get 3 documents for each queries out of which two will be same, so I need to coagulate it using set on the key value from document.

My multi search request will be like:

```
curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch --data-binary "@request"

```

where request is

```
{"index":"product"}
{"query" : {"term" : {"field1" : "xxxx1"}}}
{"index":"product"}
{"query" : {"term" : {"field2" : "xxxx2"}}}
{"index":"product"}
{"query" : {"term" : {"field1" : "xxxx3"}}}
```

---

<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:** [December 28, 2017, 6:48pm UTC](https://discuss.elastic.co/t/bool-query-with-multiple-term-queries-inside-should-or-multisearch-queries/113385/2 "2017-12-28T18:48:22Z")

</div>

Bool queries should be reasonably fast. I would go with the first approach because it makes things simpler, especially if there is overlap between the matches of each should clause.

---

<div class="post-metadata">

**Author:** ![prakharjain17](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@prakharjain17](https://discuss.elastic.co/u/prakharjain17)\
**Post date:** [January 1, 2018, 6:06am UTC](https://discuss.elastic.co/t/bool-query-with-multiple-term-queries-inside-should-or-multisearch-queries/113385/3 "2018-01-01T06:06:29Z")

</div>

Just asking, are bool queries done in parallel in lucene, because I think its been done at lucene level.  
Will it be faster if there is no overlap between matches?  
or multisearch will be faster?

---

<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:** [January 29, 2018, 6:07am UTC](https://discuss.elastic.co/t/bool-query-with-multiple-term-queries-inside-should-or-multisearch-queries/113385/4 "2018-01-29T06:07:03Z")

</div>

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