gpt4 book ai didi

elasticsearch - 在 Elasticsearch 中定义字符串数组字段

转载 作者:行者123 更新时间:2023-12-02 23:46:19 32 4
gpt4 key购买 nike

如何定义一个接受诸如[“A”,“B”,“C”]之类的字符串数组的字段。

我尝试执行以下操作:
在索引中创建了一个字段:

    {
"properties":
{
"date": {"type": "date"},
"imageUrls": { "type": "nested" },
}
}

我写文件
..../_doc/1
方法:POST

body :
{
"imageUrls": ["A", "B", "C"]
}

总是出现此错误:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "object mapping for [imageUrls] tried to parse field [null] as object, but found a concrete value"
}
],
"type": "mapper_parsing_exception",
"reason": "object mapping for [imageUrls] tried to parse field [null] as object, but found a concrete value"
},
"status": 400
}

最佳答案

嵌套映射中不允许使用单个值。从docs-系统

allows arrays of objects to be indexed in a way that they can be queried independently of each other.



也就是说,
PUT ahm
{
"mappings": {
"properties": {
"date": {
"type": "date"
},
"imageUrls": {
"type": "nested",
"properties": {
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
}

然后
POST ahm/_doc
{
"imageUrls": [
{
"url": "A"
},
{
"url": "B"
},
{
"url": "C"
}
]
}

这是非常荒谬的,但是如果将更多属性添加到数组对象,它将开始变得有意义。

关于elasticsearch - 在 Elasticsearch 中定义字符串数组字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61042137/

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