gpt4 book ai didi

elasticsearch - Elasticsearch copy_to 字段未填充

转载 作者:行者123 更新时间:2023-12-02 22:12:12 25 4
gpt4 key购买 nike

我正在尝试将 Elastic Search 5.6 中的主标题字段复制到另一个字段:index:false,因此我可以使用该字段来匹配准确的值。

但是。重新索引后,使用_source:["exact_hoofdtitel"]进行搜索,"exact_hoofdtitel"字段没有填入"hoofdtitel"的值。

PUT producten_prd_5_test
{
"aliases": {},
"mappings": {
"boek": {
"properties": {
"hoofdtitel": {
"type": "text",
"copy_to": [
"suggest-hoofdtitel", "exact_hoofdtitel"
]
},
"suggest-hoofdtitel": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": false,
"preserve_position_increments": true,
"max_input_length": 50
},
"exact_hoofdtitel":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"index":false
}
}
},
}
}
},
"settings": {
"number_of_shards": "1",
"number_of_replicas": "0"
}
}


GET producten_prd_5_test/_search
{
"_source":["hoofdtitel","exact_hoofdtitel"]
}


hits": [
{
"_index": "producten_prd_5_test",
"_type": "boek",
"_id": "9781138340671",
"_score": 1,
"_source": {
"hoofdtitel": "The Nature of the Firm in the Oil Industry"
}
},

最佳答案

我相信不用copy_to也能达到你想要的效果.让我向您展示如何以及为什么在这里不需要它。

如何在同一个字段上进行全文查询和完全匹配查询?

这可以通过 fields 来完成映射属性。基本上,使用以下映射:

PUT producten_prd_5_test_new
{
"aliases": {},
"mappings": {
"boek": {
"properties": {
"hoofdtitel": {
"type": "text", <== analysing for full text search
"fields": {
"keyword": {
"type": "keyword" <== analysing for exact match
},
"suggest": {
"type": "completion", <== analysing for suggest
"analyzer": "simple",
"preserve_separators": false,
"preserve_position_increments": true,
"max_input_length": 50
}
}
}
}
}
}
}

您将告诉 Elasticsearch 对同一字段进行三次索引:一次用于全文搜索,一次用于精确匹配,一次用于建议。

可以通过 term 进行精确搜索像这样查询:

GET producten_prd_5_test_new/_search
{
"query": {
"term": {
"hoofdtitel.keyword": "The Nature of the Firm in the Oil Industry"
}
}
}

为什么exact_hoofdtitel字段没有出现在返回的文档中?

因为 copy_to不改变来源:

The original _source field will not be modified to show the copiedvalues.

它的工作原理类似于 _all字段,允许您将多个字段的值连接到一个虚构的字段中,并以一种特殊的方式对其进行分析。

index: false 字段执行 copy_to 是否有意义?

使用 index: false 时,该字段将不会被分析并且不可搜索(就像您的示例中的字段 exact_hoofdtitel.keyword)。

如果您想在该字段上进行关键字聚合,这样做可能仍然有意义:

GET producten_prd_5_test/_search
{
"aggs": {
"by copy to": {
"terms": {
"field": "exact_hoofdtitel.keyword"
}
}
}
}

这将返回如下内容:

{
"aggregations": {
"by copy to": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "The Nature of the Firm in the Oil Industry",
"doc_count": 1
}
]
}
}
}

关于elasticsearch - Elasticsearch copy_to 字段未填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54126804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com