简体   繁体   English

如何在弹性搜索中比较两个文本字段

[英]How to compare two text fields in elastic search

I have a need to compare two text fields in elastic search, but they are text fields.我需要在弹性搜索中比较两个文本字段,但它们是文本字段。 For normal fields I can use script to compare using doc['field'].value, but is there a way to do the same for text fields.对于普通字段,我可以使用脚本来比较 doc['field'].value,但是有没有办法对文本字段执行相同的操作。

See below excerpt from ES DOCS :请参阅以下 ES DOCS 摘录:

By far the fastest most efficient way to access a field value from a script is to use the doc['field_name'] syntax, which retrieves the field value from doc values.到目前为止,从脚本访问字段值最快最有效的方法是使用 doc['field_name'] 语法,它从 doc 值中检索字段值。 Doc values are a columnar field value store, enabled by default on all fields except for analyzed text fields. Doc 值是一个列式字段值存储,默认情况下在所有字段上启用,分析的文本字段除外。

There are 2 ways known to me to access a text value from script.我知道有两种方法可以从脚本访问文本值。

  1. Map a keyword representation of a text field as well and access that field.映射文本字段的关键字表示并访问该字段。
 { "mappings": { "properties": { "name":{ "type": "text", "fields": { "keyword":{ // <======= See this "type":"keyword" } } } } } }

The keyword representation can be accessed like 'doc[name.keyword].value'关键字表示可以像 'doc[name.keyword].value' 一样访问

It is recommended to index/store keyword representation of fields for small-size text fields like 'name', 'emailId' but is not recommended for larger fields like 'description', due to memory overhead建议索引/存储字段的关键字表示,例如“name”、“emailId”等小文本字段,但不建议用于“description”等较大字段,因为内存开销较大

  1. Another way is to enable field data on the text field and access that field.另一种方法是在文本字段上启用字段数据并访问该字段。

Fielddata is disabled on text fields by default.默认情况下,在文本字段上禁用 Fielddata。 Set fielddata=true on [ your_field_name ] in order to load fielddata in memory by uninverting the inverted index.在 [ your_field_name ] 上设置fielddata=true以通过反转倒排索引将fielddata=true加载到内存中。 Note that this can however use significant memory.请注意,这可能会占用大量内存。

It is not recommended to use the field-data over the text fields however.但是,不建议在文本字段上使用字段数据。

Note: Please do add details on why you need comparison and what kind of comparison is required on 'text' fields.注意:请添加详细说明为什么需要比较以及“文本”字段需要哪种比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM