Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch Elasticsearch中嵌套数组的查询_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Logstash_Kibana_Elastic Stack_Elk - Fatal编程技术网 elasticsearch Elasticsearch中嵌套数组的查询,elasticsearch,logstash,kibana,elastic-stack,elk,elasticsearch,Logstash,Kibana,Elastic Stack,Elk" /> elasticsearch Elasticsearch中嵌套数组的查询,elasticsearch,logstash,kibana,elastic-stack,elk,elasticsearch,Logstash,Kibana,Elastic Stack,Elk" />

elasticsearch Elasticsearch中嵌套数组的查询

elasticsearch Elasticsearch中嵌套数组的查询,elasticsearch,logstash,kibana,elastic-stack,elk,elasticsearch,Logstash,Kibana,Elastic Stack,Elk,我有一个对象,我想索引到Elasticsearch索引中。对象内的某些字段中有一个嵌套的JSON对象数组。例如: "history":[ {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p",&quo

我有一个对象,我想索引到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"}}
        ],
"history":
        {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}}
我用于此字段的映射是:

{
  "mappings": {
    "properties": {
      "history" : {
        "type" : "nested",
        "properties": {
          "color": {"type" : "keyword"},
          "from" : {"type" : "keyword"},
          "to" : {"type" : "keyword"},
          "flags" : {"type" : "keyword"},
          "san" : {"type" : "keyword"},
          "ts" : {
            "type" : "nested"
          }
        }
      }
    }
  }
}
我面临的问题是,当我将对象放入索引时,如果历史字段中存储了多个对象,则映射将不起作用。在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"
  }
}
未填充我在映射中指定的不同嵌套字段

我的映射有问题吗?如果“历史记录”字段只有一个对象,则该选项似乎有效,例如:

"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"}}
        ],
"history":
        {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}}

但对于多个对象,它无法正确映射。可能有什么问题?

您好,我很抱歉,您的映射没有任何问题。如何为这些数据编制索引?我认为你的问题在于索引部分,我使用Kibana中的控制台将对象放入我创建的索引中。