user1741694
user1741694

Reputation: 247

Elasticsearch exact match of specific field(s)

I'm trying to filter my elasticsearch index by specific fields, the "country" field to be exact. However, I keep getting loads of other results (other countries) back that are not exact.

Please could someone point me in the right direction.

I've tried the following searches:

GET http://127.0.0.1:9200/decision/council/_search
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "country": "Algeria"
        }
      }
    }
  }
}

Here is an example document:

{
  "_index": "decision",
  "_id": "54290140ec882c6dac5ae9dd",
  "_score": 1,
  "_type": "council",
  "_source": {
    "document": "DEV DOCUMENT"
    "id": "54290140ec882c6dac5ae9dd",
    "date_updated": 1396448966,
    "pdf_file": null,
    "reported": true,
    "date_submitted": 1375894031,
    "doc_file": null,
    "country": "Algeria"
  }
}

Upvotes: 1

Views: 824

Answers (1)

Abdel
Abdel

Reputation: 161

You can use the match_phrase query instead

POST http://127.0.0.1:9200/decision/council/_search
{
   "query" : {
      "match_phrase" : { "country" : "Algeria"}
            }
}

Upvotes: 2

Related Questions