elasticsearch | Querying document with list with term and terms not working elasticsearch | Querying document with list with term and terms not working elasticsearch elasticsearch

elasticsearch | Querying document with list with term and terms not working


By default, you are using the Standard Analyzer, which lowercases your input.

Querying for retail (lowercase) will yield the expected result:

curl -XGET localhost:9200/twitter/tweet/_search -d '{  "query": {    "term": {      "community": {        "value": "retail"      }    }  }}'

result:

{  "took": 3,  "timed_out": false,  "_shards": {    "total": 5,    "successful": 5,    "failed": 0  },  "hits": {    "total": 1,    "max_score": 0.15342641,    "hits": [      {        "_index": "twitter",        "_type": "tweet",        "_id": "1",        "_score": 0.15342641,        "_source": {          "community": [            "Cortez",            "Retail",            "NetAtmo"          ],          "date": "2009-11-10T14:12:12",          "memberID": 3,          "validation": "valid",          "dal_is_installed": true,          "dal_is_flowing": true,          "is_flowing_dal_tablet": true,          "is_flowing_dal_computer": false,          "is_flowing_dal_smartphone": true,          "ss_is_installed": true,          "ss_is_flowing": true,          "ss_survey_responded_count": 5,          "dal_mobile_activity_count": 5,          "dal_tab_activity_count": 5,          "dal_computer_activity_count": 5,          "status": "verified"        }      }    ]  }}

You either need to lowercase your request, or set up a different analyzer.


If you are fine with full-text search on field community, tell elasticsearch to match phrase instead of your term query,

   "community": {                  "type": "string"               },

And query like,

POST http://yourEsHost:9200/INDEX/TYPE/_search{   "query": {     "match_phrase": {        "community": "Retail"     }    } }

But

It will also give results when you query like,

POST http://yourEsHost:9200/INDEX/TYPE/_search{   "query": {     "match_phrase": {        "community": "Cortez Retail"     }    } }

or

POST http://yourEsHost:9200/INDEX/TYPE/_search{   "query": {     "match_phrase": {        "community": "Cortez Retail NetAtmo"     }    } }

Reference

multi-value fields