Flashing slashes in elasticsearch

I do a general search with elasticsearch (1.7), and everything is fine, except that I have quotation numbers. The account number field is not an identifier field and is "not_analyzed".

If I search by account number, for example. AC / 1234 / A01, then I get thousands of results, apparently because it does a regular expression search (?).

{ "query" : { "query_string" : {"query" : "AC/1234/A01"} } } 

I can get the result that I want by doing an exact match search

  { "query" : { "query_string" : {"query" : "\"AC/1234/A01\""} } } 

This really gives me the result I want, and will probably put the score as a backup option (surrounding all “one word” searches with quotes). However, I think that if they search for several words, including the account number, I will return to thousands of results, and although I do not see the meaning of this search, I would like to avoid this.

Essentially, I have a Java application requesting an elastic search, and I would like to avoid all the slashes introduced in the GUI.

My googling told me that

 { "query" : { "query_string" : {"query" : "AC\\/1234\\/A01"} } } 

should do it, but it doesn’t matter, the request works, but I still get thousands of results.

Can someone point me in the right direction?

+5
source share
1 answer

You should get what you want without avoiding anything by simply specifying a keyword analyzer for the query string, for example:

 { "query" : { "query_string" : { "query" : "AC/1234/A01", "analyzer": "keyword" <---- add this line } } } 

If you do not, the standard analyzer is used (and will tokenize the query string) regardless of the type of your field or not_analyzed or not.

+9
source

All Articles