gpt4 book ai didi

elasticsearch - 是否可以在 Elasticsearch 中获取 copy_to 字段的内容?

转载 作者:行者123 更新时间:2023-11-29 02:46:32 26 4
gpt4 key购买 nike

我正在使用 Elasticsearch v2.3.0。假设我有一个带有映射的索引:

{
"mappings": {
"post": {
"dynamic": false,
"_source": {
"enabled": true
},
"properties": {
"text": {
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"analyzer": "text_analyzer",
"type": "string"
},
"subfield": {
"properties": {
"subsubfield": {
"properties": {
"subtext": {
"index": "no",
"analyzer": "text_analyzer",
"type": "string",
"copy_to": "text"
}
}
}
}
}
},
"_all": {
"enabled": false
}
}
}

因此,由于 copy_tosubfield.subsubfield.subtext 中的文本被复制到文本 field。如果您查询一个帖子,那么只有来自 text 的数据显示在 text 字段中,因为 _source 没有被修改。如果要获取所有文本,则应在客户端聚合所有字段。如果有很多子字段,这可能会很不方便。

是否有一个神奇的查询,它允许获取 text 字段并将所有文本复制到它?

最佳答案

text 字段的映射中设置 "store":"yes"您应该能够使用 fields 获取它

示例:

put test/test/_mapping
{
"properties" : {
"name" : { "type" : "string","copy_to": "text"},
"text" : {"type" : "string" ,"store" :"yes"},
"subfield": {
"properties": {
"subsubfield": {
"properties": {
"subtext": {
"index": "no",
"type": "string",
"copy_to": "text"
}
}
}
}
}
}

}

put test/test/1
{
"name" : "hello",
"subfield" : {
"subsubfield" : [
{"subtext" : "soundgarden" },
{"subtext" : "alice in chains" },
{"subtext" : "dio" }
]
}
}

post test/_search
{
"stored_fields": [
"text"
]
}

结果

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"fields": {
"text": [
"hello",
"soundgarden",
"alice in chains",
"dio"
]
}
}
]
}
}

关于elasticsearch - 是否可以在 Elasticsearch 中获取 copy_to 字段的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36618549/

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