I was asked this question when I was reporting to my superiors today, and I didn't come back.
English Original:
Https://www.elastic.co/guide/en/elasticsearch/guide/current/_queries_and_filters.html
The first thing we talked about is structured query statements, in fact we can use two structured statements: Structured queries (query DSL) and structured filtering (filter DSL). Queries are very similar to filter statements, but they vary slightly depending on the purpose of the use.
A filter statement asks if the field value for each document contains a specific value:
created
is the date range in 2013
2014
?
status
Does the field contain the word "published"?
lat_lon
is the geographic location in the field less than 10km away from the target point?
A query statement is similar to a filter statement, but with a different method of asking:
Query statements ask how the field values of each document match a particular value.
A typical use of a query statement is to find a document:
- Find a
full text search
document that best matches this word
- Find documents that contain words
run
, but also contain runs
, running
, jog
or sprint
- The closer you
quick
brown
get to fox
---words, the higher the relevance of the document
- The more
lucene
relevant the document is, the more it is identified, search
or java
---the identity word.
A query statement calculates the relevance of each document to the query statement, gives a relevance score _score
, and sorts the matching documents by relevance. This scoring method is ideal for a full-text search with no fully configured results.
Performance differences
The result set using a filter statement-a simple list of documents-is handy for fast matching operations and memory storage, which requires only 1 bytes per document. These cached filtered result sets are very efficient in combination with subsequent requests.
Query statements not only look for matching documents, they also need to calculate the relevance of each document, so it is generally more time consuming than filtering statements, and query results are not cacheable.
Thanks to the inverted index, a simple query statement that matches only a small number of documents will be more efficient in the millions document than a cached filter statement, or even slightly prevail. However, in general, a cached filter query is far better than the execution efficiency of a query statement.
The purpose of the filter statement is to narrow the matching document result set, so you need to check the filter criteria carefully.
What is the use of
In principle, when using query statements for full-text searches or other relevance scoring, all that is left is to filter the statements.
Elasticsearch Query and Filtering