anina
anina

Reputation: 21

elasticsearch query string with hyphens

Elasticsearch 5.6

I have my field defined as text field, with a whitespace analyzer in order to avoid splitting on hyphens.

I want to query it, using query string query, like:

{
    "query": {     
      "query_string": {
        "query": "CODE-13-006",
        "default_operator": "AND",
        "analyzer": "whitespace"
      }
   }
}

so if i don't specify which field i want to search on, (as far as i understood) it supposed to query "*" fields. Even though query like one above doesn't return anything, but if i ask for specifc field, it finds a match.

Any hint?

Upvotes: 1

Views: 2376

Answers (2)

anina
anina

Reputation: 21

Ok, so in case somebody had a similar doubts...

My problem was, that even though I was querying an _all field (concatenating values from all the other fields), I forgot that by default it uses a standard analyzer (which separate tokens on hyphens). So even though my field was using a keyword analyzer, on my _all query I couldn't find it - simply because it got split by a standard analyzer.

Stupid mistake, but maybe will help somebody in the future;)

Upvotes: 1

Farhoud
Farhoud

Reputation: 91

i think the answer is here ElasticSearch: How to search for a value in any field, across all types, in one or more indices? for elastic 5.6 u can use field name _all

Upvotes: 0

Related Questions