美文网首页
ES中的term查询

ES中的term查询

作者: handsomemao666 | 来源:发表于2020-09-28 22:35 被阅读0次

term级别查询(term-level queries)
你可以使用term级别查询在结构化的数据中根据精确的值进行查找,例如日期范围、IP地址、价格、产品ID。term级别查询不会对查询语句进行分词,而是精确的去匹配结构化数据中的字段值。

1、 Exists query

Returns documents that contain an indexed value for a field.

An indexed value may not exist for a document’s field due to a variety of reasons:

  • The field in the source JSON is null or []
  • The field has "index" : false set in the mapping
  • The length of the field value exceeded an ignore_above setting in the mapping
  • The field value was malformed and ignore_malformed was defined in the mapping

Example:
GET /_search { "query": { "exists": { "field": "user" } } }

While a field is deemed non-existent if the JSON value is null or [], these values will indicate the field does exist:

  • Empty strings, such as "" or "-"
  • Arrays containing null and another value, such as [null, "foo"]
  • A custom null-value, defined in field mapping

Find documents missing indexed values
To find documents that are missing an indexed value for a field, use the must_not with the exists query.
Exable:
GET /_search { "query": { "bool": { "must_not": { "exists": { "field": "user.id" } } } } }

2、Fuzzy query

Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.

An edit distance is the number of one-character changes needed to turn one term into another. These changes can include:

  • Changing a character (box → fox)
  • Removing a character (black → lack)
  • Inserting a character (sic → sick)
  • Transposing two adjacent characters (act → cat)

To find similar terms, the fuzzy query creates a set of all possible variations, or expansions, of the search term within a specified edit distance. The query then returns exact matches for each expansion.
Example:
GET /_search { "query": { "fuzzy": { "user.id": { "value": "ki" } } } }
Example:
GET /_search { "query": { "fuzzy": { "user.id": { "value": "ki", "fuzziness": "AUTO", "max_expansions": 50, "prefix_length": 0, "transpositions": true, "rewrite": "constant_score" } } } }
Parameters
<field>
(Required, object) Field you wish to search.
value
(Required, string) Term you wish to find in the provided <field>.
fuzziness
(Optional, string) Maximum edit distance allowed for matching.
AUTO
Generates an edit distance based on the length of the term. Low and high distance arguments may be optionally provided AUTO:[low],[high]. If not specified, the default values are 3 and 6, equivalent to AUTO:3,6 that make for lengths:
0..2 Must match exactly
3..5 One edit allowed
5+ Two edits allowed
AUTO should generally be the preferred value for fuzziness.
max_expansions
(Optional, integer) Maximum number of variations created. Defaults to 50.
prefix_length
(Optional, integer) Number of beginning characters left unchanged when creating expansions. Defaults to 0.
transpositions
(Optional, boolean) Indicates whether edits include transpositions of two adjacent characters (ab → ba). Defaults to true.
rewrite
(Optional, string) Method used to rewrite the query.

3、IDS

Returns documents based on their IDs. This query uses document IDs stored in the _id field.
Example
GET /_search { "query": { "ids" : { "values" : ["1", "4", "100"] } } }

4、Prefix query

Returns documents that contain a specific prefix in a provided field.
Example:
GET /_search { "query": { "prefix": { "user.id": { "value": "ki" } } } }

相关文章

  • ES中的term查询

    term级别查询(term-level queries)你可以使用term级别查询在结构化的数据中根据精确的值进行...

  • Elasticsearch TermQuery 详解

    JavaClient 查询ES 1、term query 分词精确查询,查询hotelName 分词后包含 hot...

  • ES 全文搜索

    ES 全文搜索 全文搜索 使用了match查询的多词查询只是简单地将生成的term查询包含在了一个bool查询中。...

  • 转~elasticsearch 查询(match和term)

    elasticsearch 查询(match和term) es中的查询请求有两种方式,一种是简易版的查询,另外一种...

  • term,match,match_phrase的区别

    term查询是基于词项的查询,而且当设置为term查询时,es不会对这个词做任何处理,但是在文本进行分词时,通常都...

  • ES查询相关

    ES查询相关 查询所有数据、搜索所有数据 或者 term与terms 查询name="python"的所有数据 t...

  • elasticsearch 查询

    Python代码中动态修改可查询的最大term数 查询es所有的items 利用每个产品名称和其他公司中的产品名称...

  • Lucene相似度

    Lucene的查询过程是:首先在词典中查找每个Term,根据Term获得每个Term所存在的文档链表;然后根据查询...

  • ES6.x 各种查询

    term & terms 查询 term 查询 terms terms 和 term 的查询 机制是一样,都不会将...

  • Elasticsearch第10节 基本查询

    一、英文检索 1. term和terms查询 term query 会去 倒排索引中寻找 确切的term,它并 不...

网友评论

      本文标题:ES中的term查询

      本文链接:https://www.haomeiwen.com/subject/dxvjuktx.html