带有嵌套字段的 Elasticsearch 插入适用于 Kibana,但不适用于 cURL

Elasticsearch insert with nested fields works on Kibana but not with cURL

我正在尝试在 ElasticSearch 中插入一个包含嵌套字段的文档。我通过使用 PUT 命令将字段标记为嵌套来创建索引:

PUT nested_test
{
    "mappings": {
        "_doc": {
            "properties": {
                "nested_field": {
                     "type": "nested"
                }
            }
        }
    }
}

现在,我使用以下命令从 Kibana 控制台将数据插入此索引:

POST nested_test/_doc/1234
{
    "created_time": "2018-01-01 01:52:53",
    "status": "Ok",
    "nested_field": [
        {
            "col4": 0,
            "col5": 0,
            "col3": 0,
            "col1": 3234253,
            "col2": 1
        },
        {
            "col5": 0,
            "col4": 0,
            "col2": 1,
            "col1": 34241,
            "col3": 2
        },
        {
            "col5": 0,
            "col4": 0,
            "col2": 1,
            "col1": 775756,
            "col3": 0
        }
    ]
}

这非常有效,我能够看到索引中的数据,嵌套字段按预期进行了索引。

但是如果我将相同的 json 与 curl 一起使用,我会收到一条错误响应:

"error" : {
    "type" : "illegal_argument_exception",
    "reason" : "object mapping [nested_field] can't be changed from nested to non-nested"
  }

使用的确切 curl 命令是:

curl -XPOST -H 'Content-Type: application/json'  http://someurl:9200/nested_test/doc/_bulk?pretty --data-binary @es.json

请注意,我已尝试使用 POST 和 PUT。 无法理解为什么同一索引上的相同 json 适用于 Kibana 而不适用于 cURL。任何帮助,将不胜感激。谢谢

我看到了问题。在您的映射中,您定义了 _doc 映射类型,但您在 curl 中使用了 doc。以下卷曲应该有效:

curl -XPOST -H 'Content-Type: application/json'  http://someurl:9200/nested_test/_doc/_bulk?pretty --data-binary @es.json