ElasticSearch Bool Filter with a phrase (instead of a single word / tag)

In elastic search this filter

{ "bool": { "must": { "term": { "article.title": "google" } } } } 

Correctly returns articles with "google" in the title.

However

 { "bool": { "must": { "term": { "article.title": "google earth" } } } } 

It does not return any results, despite the fact that the title contains articles with the exact words "google earth". I would like it to do.

Full request:

 { "size": 200, "filter": { "bool": { "must": { "term": { "article.title": "google maps" } } } }, { "range": { "created_date": { "from": "2013-01-11T02:14:03.352Z" } } }] } } 

As you can see, I don’t have a β€œrequest” - just a filter, size and range. Therefore, I believe that ElasticSearch uses the default analyzer ...?

What? I do not understand?


EDIT: For those looking for a solution, here is my filter:

 { "query": { "bool": { "must": { "must_match": { "article.title": "google earth" } } } } } 

Node, that (1) we wrapped the bool filter with a "query" and (2) the "term" was changed to "must_match", which leads to the agreement of the whole phrase (as opposed to the "match" that will be searched in the .title article with a standard analyzer on Google Earth).

The full query looks like this:

 { "size": 200, "filter": { "query": { "bool": { "must": { "must_match": { "article.title": "google earth" } } } } } } 

FWIW, the reason I have this condition in the filter field (as opposed to using a standard query) is because sometimes I want to use must_not instead of must_not, and sometimes I also add other query elements .

+6
source share
4 answers

Elasticsearch does not use a parser at all, because you used a term query that searches for exact terms.

The title field is parsed (unless you specify otherwise), so "google earth" will be indexed as two members ["google","earth"] . Therefore, the term query for "google" works, but the term query for "google earth" does not indicate that the EXACT member does not exist.

If you use the match query instead, then your queries will be parsed before searching.

+9
source

For those who stumbled upon this very recently, keep in mind that a shorter way of presenting

 {"query":{"bool":{"must":{"must_match":{"article.title":"google earth"}}}}} 

It has

 {"query":{"match_phrase":{"article.title":"google earth"}}} 
0
source

I solved this by blowing up a missing phrase, so it just changed.

 {"bool":{"must":{"term":{"article.title":"google earth"}}}} 

to

 {"bool":{"must":{"term":{"article.title":["google", "earth"]}}}} 

This is not very good and may be too slow if you have a lot of queries, but it works.

NOTE. I just found out that this will also return any results using google or earth.

0
source

Using Elasticsearch 5.4.2., My solution developed as follows:

 {"query": { "bool": { "must": { "match_phrase": { "article.title": "google earth"}}}}} 

Hope this helps someone.

0
source

All Articles