elasticsearch中的logstash查询嵌套数组

whhtz7ly  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(0)|浏览(273)

我有一个对象,我想索引到elasticsearch索引中。对象中的一些字段中有一个嵌套的json对象数组。例如:

"history":[
        {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}},
        {"color":"b","from":"e7","to":"e5","flags":"b","piece":"p","san":"e5","ts":{"$numberLong":"1586861527710"}},
        {"color":"w","from":"f2","to":"f4","flags":"b","piece":"p","san":"f4","ts":{"$numberLong":"1586861531620"}},
        {"color":"b","from":"d8","to":"h4","flags":"n","piece":"q","san":"Qh4#","ts":{"$numberLong":"1586861533363"}}
        ],

我用于此字段的Map是:

{
  "mappings": {
    "properties": {
      "history" : {
        "type" : "nested",
        "properties": {
          "color": {"type" : "keyword"},
          "from" : {"type" : "keyword"},
          "to" : {"type" : "keyword"},
          "flags" : {"type" : "keyword"},
          "san" : {"type" : "keyword"},
          "ts" : {
            "type" : "nested"
          }
        }
      }
    }
  }
}

我面临的问题是,当我将对象放入索引时,如果history字段中存储了多个对象,那么Map就不起作用。在kibana中,历史字段存储如下:

{
  "color": "w",
  "from": "g2",
  "to": "g4",
  "flags": "b",
  "piece": "p",
  "san": "g4",
  "ts": {
    "$numberLong": "1586861525811"
  }
},
{
  "color": "b",
  "from": "e7",
  "to": "e5",
  "flags": "b",
  "piece": "p",
  "san": "e5",
  "ts": {
    "$numberLong": "1586861527710"
  }
},
{
  "color": "w",
  "from": "f2",
  "to": "f4",
  "flags": "b",
  "piece": "p",
  "san": "f4",
  "ts": {
    "$numberLong": "1586861531620"
  }
},
{
  "color": "b",
  "from": "d8",
  "to": "h4",
  "flags": "n",
  "piece": "q",
  "san": "Qh4#",
  "ts": {
    "$numberLong": "1586861533363"
  }
}

我在Map中指定的不同嵌套字段没有填充。
我的Map有问题吗?如果history字段只有一个对象(例如:

"history":
        {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}}

但对于多个对象,它无法正确Map。有什么问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题