gpt4 book ai didi

json - 此弹性json查询映射有什么问题?

转载 作者:行者123 更新时间:2023-12-03 01:15:33 25 4
gpt4 key购买 nike

我正在尝试使用嵌套的JSON查询数据库记录。这是我的查询-

"query": {
"nested": {
"path": "metadata.technical",
"query": {
"bool": {
"must": [
{
"term": {
"metadata.technical.key": "techcolor"
}
},
{
"term": {
"metadata.technical.value": "red"
}
}
]
}
}
}
}
这是我的mapping.json中的这一部分-
"metadata": {
"include_in_parent": true,
"properties": {
"technical": {
"type": "nested",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
而且我的表具有“值”列,其内容是-
{"technical":
{
"techname22": "test",
"techcolor":"red",
"techlocation": "usa"
}
}
为什么我无法获得任何结果?仅供引用,我正在使用ES 1.7。谢谢你的帮助。

最佳答案

为了尊重您定义的映射,示例文档应如下所示:

{
"technical": [
{
"key": "techname22",
"value": "test"
},
{
"key": "techcolor",
"value": "red"
},
{
"key": "techlocation",
"value": "usa"
}
]
}
使用上述结构更改文档将使您的查询保持原样。
该文档的真实映射:
{
"technical": {
"techname22": "test",
"techcolor": "red",
"techlocation": "usa"
}
}
更像这样:
{
"include_in_parent": true,
"properties": {
"technical": {
"type": "nested",
"properties": {
"techname22": {
"type": "string"
},
"techcolor": {
"type": "string"
},
"techlocation": {
"type": "string"
}
}
}
}
}
如果所有键都是动态的并且事先未知,则还可以将映射也配置为动态的,即不要在嵌套类型中定义任何字段,如果映射中尚不存在则将添加新字段:
{
"include_in_parent": true,
"properties": {
"technical": {
"type": "nested",
"properties": {
}
}
}
}

关于json - 此弹性json查询映射有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62695994/

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