# Get different results when using term with the same args

**URL:** <https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255>\
**Category:** Elasticsearch\
**Created:** [March 3, 2017, 4:06am UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255 "2017-03-03T04:06:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![feiTian](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@feiTian](https://discuss.elastic.co/u/feiTian)\
**Post date:** [March 3, 2017, 4:06am UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/1 "2017-03-03T04:06:31Z")

</div>

Hi,  
I am trying to find out a way do multi-value exact search. But I met a very wired issue. It returns different results if the sequence of args is different.  
I am using term to filter:

```
{"filter": {"term": {"ContentMap.gls": [79,194,121]}}}"

result:
{"jsonResponse": "{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":4,"max_score":1.0,"hits":[{"_index":"discover","_type":"type_id","_id":"BRAND:8a5974f4-8b50-4790-b02d-dd0e347c476b","_score":1.0,"_source":{"ContentMap":{"gls":[121]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:42150c34-8eb8-49cf-836d-b2713305d6f8","_score":1.0,"_source":{"ContentMap":{"gls":[121]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:19373b45-b1cf-4988-adb3-3928a3a2d34c","_score":1.0,"_source":{"ContentMap":{"gls":[194,121,79]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:cf523ca2-0182-4f19-97ac-03fe6541b17d","_score":1.0,"_source":{"ContentMap":{"gls":[121]}}}]}}"}

{"filter": {"term": {"ContentMap.gls": [79,121,194]}}}"

{"jsonResponse": "{"took":4,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":10,"max_score":1.0,"hits":[{"_index":"discover","_type":"type_id","_id":"BRAND:0607cbbf-27ed-4671-a9f1-e459a1f0fa0a","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:c2fa70e0-b2b0-4bde-97af-57b18c3c4876","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:19373b45-b1cf-4988-adb3-3928a3a2d34c","_score":1.0,"_source":{"ContentMap":{"gls":[194,121,79]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:2809c901-107d-477c-86cf-993abfda0bb7","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:7d4e30d2-0cb8-4d9a-a1e6-a7f34bfb7bdf","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"HASHTAG:65d69173-4ac7-487c-9fab-bace3421a9bb","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"HASHTAG:de940006-9693-4713-bc74-d77e575b3e09","_score":1.0,"_source":{"ContentMap":{"gls":[309,193,79,23,194,241]}}},{"_index":"discover","_type":"type_id","_id":"BRAND:89633bd7-2959-45b4-8725-12f9e097e62c","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"KOL:fb452313-86b7-4d52-bd3e-3eab0729285f","_score":1.0,"_source":{"ContentMap":{"gls":[194]}}},{"_index":"discover","_type":"type_id","_id":"D#HASHTAG:f567a298-3930-4d11-a8ad-1f1829c0eb9b","_score":1.0,"_source":{"ContentMap":{"gls":[197,229,421,201,21,241,309,193,200,194]}}}]}}"}

```

I am using the latest version of ElasticSearch.  
Any help will be apprecated.

---

<div class="post-metadata">

**Author:** ![feiTian](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@feiTian](https://discuss.elastic.co/u/feiTian)\
**Post date:** [March 3, 2017, 4:07am UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/2 "2017-03-03T04:07:46Z")

</div>

Resut-1:  
{"jsonResponse": "{"took":2,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":4,"max\_score":1.0,"hits":[{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:8a5974f4-8b50-4790-b02d-dd0e347c476b","\_score":1.0,"\_source":{"ContentMap":{"gls":[121]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:42150c34-8eb8-49cf-836d-b2713305d6f8","\_score":1.0,"\_source":{"ContentMap":{"gls":[121]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:19373b45-b1cf-4988-adb3-3928a3a2d34c","\_score":1.0,"\_source":{"ContentMap":{"gls":[194,121,79]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:cf523ca2-0182-4f19-97ac-03fe6541b17d","\_score":1.0,"\_source":{"ContentMap":{"gls":[121]}}}]}}"}

---

<div class="post-metadata">

**Author:** ![feiTian](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@feiTian](https://discuss.elastic.co/u/feiTian)\
**Post date:** [March 3, 2017, 4:08am UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/3 "2017-03-03T04:08:27Z")

</div>

Result-2:  
{"jsonResponse": "{"took":4,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":10,"max\_score":1.0,"hits":[{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:0607cbbf-27ed-4671-a9f1-e459a1f0fa0a","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:c2fa70e0-b2b0-4bde-97af-57b18c3c4876","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:19373b45-b1cf-4988-adb3-3928a3a2d34c","\_score":1.0,"\_source":{"ContentMap":{"gls":[194,121,79]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:2809c901-107d-477c-86cf-993abfda0bb7","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:7d4e30d2-0cb8-4d9a-a1e6-a7f34bfb7bdf","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"HASHTAG:65d69173-4ac7-487c-9fab-bace3421a9bb","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"HASHTAG:de940006-9693-4713-bc74-d77e575b3e09","\_score":1.0,"\_source":{"ContentMap":{"gls":[309,193,79,23,194,241]}}},{"\_index":"discover","\_type":"type\_id","\_id":"BRAND:89633bd7-2959-45b4-8725-12f9e097e62c","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"KOL:fb452313-86b7-4d52-bd3e-3eab0729285f","\_score":1.0,"\_source":{"ContentMap":{"gls":[194]}}},{"\_index":"discover","\_type":"type\_id","\_id":"D#HASHTAG:f567a298-3930-4d11-a8ad-1f1829c0eb9b","\_score":1.0,"\_source":{"ContentMap":{"gls":[197,229,421,201,21,241,309,193,200,194]}}}]}}"}

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [March 3, 2017, 12:52pm UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/4 "2017-03-03T12:52:38Z")

</div>

You want to use the terms query, not the term query (notice the **s** at the end). All arguments except the first one seem to be ignored by the term query. We don't consider this as a valid query, and throw an appropriate exception message in ES v5.0:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[term] query does not support array of values",
        "line": 4,
        "col": 15
      }
    ],
    "type": "parsing_exception",
    "reason": "[term] query does not support array of values",
    "line": 4,
    "col": 15
  },
  "status": 400
}

```

---

<div class="post-metadata">

**Author:** ![feiTian](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@feiTian](https://discuss.elastic.co/u/feiTian)\
**Post date:** [March 5, 2017, 2:17am UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/5 "2017-03-05T02:17:27Z")

</div>

Thanks for your answer. I tried terms, it works well.  
Actually I want to search records whose gls only contains [79,121,194] (whose gls is a subset of [79,121,194]), for example, I want it returns records whose gls is [79], or [79,121], or [79,194], or [121, 194], or [79,194,121].  
Any suggestion is appreciated!

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [March 6, 2017, 2:29pm UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/6 "2017-03-06T14:29:44Z")

</div>

You can do this with a bool query that contains three must clauses. The first must clause is a term query for 79, the second one a term query for 121 and the third one a term query for 194.

---

<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:** [April 3, 2017, 2:29pm UTC](https://discuss.elastic.co/t/get-different-results-when-using-term-with-the-same-args/77255/7 "2017-04-03T14:29:55Z")

</div>

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