“对象映射[价格]无法从批量Python上的嵌套更改为非嵌套”

时间:2017-08-15 15:13:15

标签: python elasticsearch

我正在尝试在ElasticSearch中插入一个文档,但每次我尝试在python中插入时,它都会返回一个错误。但如果我尝试从Kibana或cUrl插入,它的成功。 我已经尝试过elasticserach-dsl,但我也遇到了同样的错误。

(抱歉我的英语不好,我来自巴西:D)

我有错误:

elasticsearch.helpers.BulkIndexError: ((...)'status': 400, 'error': {'type': 
'illegal_argument_exception', 'reason': "object mapping [prices] can't be changed from nested to non-nested"}}}])

我的代码:

from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
doc = [{
            "_index": "products",
            "_type": "test_products",
            "_source": {
                [...]
                "prices": {
                    "latest": {
                        "value": 89,
                        "when": 1502795602848
                    },
                    "old": [
                        {
                            "value": 0,
                            "when": 1502795602848
                        }
                    ]
                },
                "sizes": [
                    {
                        "name": "P",
                        "available": True
                    },
                    {
                        "name": "M",
                        "available": True
                    }
                ],
                "created": "2017-08-15T08:13:22.848284"
            }
        }]
        bulk(self.es, doc, index="products")

我的ES映射:

{
  "test_products": {
    "mappings": {
      "products": {
        "properties": {
          "approved": {
            "type": "boolean"
          },
          "available": {
            "type": "boolean"
          },
          "brand": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "buyClicks": {
            "type": "integer"
          },
          "category": {
            "type": "keyword"
          },
          "code": {
            "type": "keyword"
          },
          "color": {
            "type": "nested",
            "properties": {
              "name": {
                "type": "keyword"
              },
              "value": {
                "type": "keyword"
              }
            }
          },
          "created": {
            "type": "date"
          },
          "description": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "gender": {
            "type": "keyword"
          },
          "images": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "likes": {
            "type": "integer"
          },
          "link": {
            "type": "keyword"
          },
          "name": {
            "type": "text",
            "term_vector": "yes",
            "analyzer": "nGram_analyzer",
            "search_analyzer": "whitespace_analyzer"
          },
          "prices": {
            "type": "nested",
            "properties": {
              "latest": {
                "type": "nested",
                "properties": {
                  "value": {
                    "type": "long"
                  },
                  "when": {
                    "type": "date",
                    "format": "dd-MM-yyyy||epoch_millis"
                  }
                }
              },
              "old": {
                "type": "nested",
                "properties": {
                  "value": {
                    "type": "long"
                  },
                  "when": {
                    "type": "date",
                    "format": "dd-MM-yyyy||epoch_millis"
                  }
                }
              }
            }
          },
          "redirectClicks": {
            "type": "integer"
          },
          "sizes": {
            "type": "nested",
            "properties": {
              "available": {
                "type": "boolean"
              },
              "name": {
                "type": "keyword"
              },
              "quantity": {
                "type": "integer"
              }
            }
          },
          "slug": {
            "type": "keyword"
          },
          "store": {
            "type": "keyword"
          },
          "subCategories": {
            "type": "nested",
            "properties": {
              "name": {
                "type": "keyword"
              },
              "value": {
                "type": "keyword"
              }
            }
          },
          "tags": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "text",
                "term_vector": "yes",
                "analyzer": "nGram_analyzer",
                "search_analyzer": "whitespace_analyzer"
              }
            }
          },
          "thumbnails": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

0 个答案:

没有答案