Nicholas Batura
Nicholas Batura

Reputation: 23

ElasticSearch 5.2 divides sentence with whitespaces

I have the following strings:

"hello world"
"hello"
"hello world all"

and my mapping looks like this

...
"properties": {
  "my_field": {
    "type": "string",
    "index": "not_analyzed"
  }
}
...

When I try to perform a search using simple_query_string:

{
  "query": {
    "simple_query_string" : {
        "query": "hello"
    }
  }
}

I get all three strings.

The problem is that I need only one string which is associated with "hello".

Upvotes: 2

Views: 60

Answers (1)

nikoshr
nikoshr

Reputation: 33364

Use a term query to get an exact match

{
  "query": {
    "term" : {
        "my_field": "hello"
    }
  }
}

Note that in ES 5, you can simplify your mapping by specifying a keyword type

"properties": {
  "my_field": {
    "type": "keyword"
  }
}

Upvotes: 1

Related Questions