Elasticsearch's query and filter filter

Query and Filter

 

Although we've covered query DSLs before, there are actually two kinds of DSLs: query DSLs and filter DSLs.

Filters are usually used to filter the range of documents, such as whether a field belongs to a certain type, or which time interval it belongs to

* Was the creation date between 2014-2015?

* Is the status field success?

* Is the lat_lon field within 10km of a certain coordinate?

 

The use of the query (query) is very similar to the filter, but the query tends to be more accurate.

* Highest match with full text search

* Regular match

* Contains the word run, if it contains these words: runs, running, jog, sprint, it is also considered to contain the word run

* Contains quick, brown, fox. The closer the words are, the more relevant the document is

The querier calculates how relevant each document is to a query, and then assigns the document a relevance score: _score. This score is then used to rank the matching documents for relevance. The concept of relevance lends itself well to full-text search, an area where it is difficult to give complete, "correct" answers.

Query filter performance comparison: filter does not calculate correlation, and can be cached at the same time. Therefore, filter speed is faster than query.

 

If your query is relatively coarse in scope and type, use filter; if it is precise, use query to query. 

 

Personal understanding: If you need full-text search relevance score ranking, use query, need type filtering, exact match, use filter. In addition, since filtering is to filter the retrieved results, the query needs to use indexes or key fields as much as possible.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263102&siteId=291194637