Elasticsearch Query and Filtering

Source: Internet
Author: User

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:

    • createdis the date range in 2013 2014 ?
    • statusDoes the field contain the word "published"?
    • lat_lonis 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.