Get different results when using term with the same args

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.

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]}}}]}}"}

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]}}}]}}"}

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:

{
  "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
}

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!

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.

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