Kibana 正确的方法来处理类型为“nested”的嵌套对象

kx7yvsdv  于 5个月前  发布在  Kibana
关注(0)|答案(1)|浏览(40)

我有一个类型为“nested”的数组字段。在这个字段中我有多个对象。这是JSON示例:

{
  "users" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

字符串
我希望在索引后得到相同的结构。这是我Map的一部分:

},
"users": {
    "dynamic": false,
    "type": "nested",
    "properties": {
        "first": {
            "type": "text"
         },
         "last": {
             "type": "text"
        },
    }
}


但是在索引之后,我得到了这个结构:

users
    
[
  {
    "first": [
      "John"
    ],
    "last": [
      "Smith"
    ],
  },
  {
    "first": [
      "Alice"
    ],
    "last": [
      "White"
    ],
  },]


我做错了什么?这种行为是预期的吗?我如何处理嵌套对象?
我只需要文本字段,而不是数组中的文本字段。搜索工作正常,但Map后的数据格式令人困惑。
删除索引,更改Map,刷新索引。设置动态:true和false。更改字段类型。

ghhaqwfi

ghhaqwfi1#

我用的是ES v8,运行正常。


的数据

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "users": {
        "dynamic": false,
        "type": "nested",
        "properties": {
          "first": {
            "type": "text"
          },
          "last": {
            "type": "text"
          }
        }
      }
    }
  }
}
PUT my-index-000001/_doc/1
{
  "group" : "fans",
  "users" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}
GET my-index-000001/_search
{
  "query": {
    "nested": {
      "path": "users",
      "query": {
        "bool": {
          "must": [
            { "match": { "users.first": "Alice" }},
            { "match": { "users.last":  "White" }} 
          ]
        }
      }
    }
  }
}

相关问题