简体   繁体   中英

Python Elasticsearch : Index mapping inconsistencies between ‘es.index’ and ‘es.indices.create’

I'm trying to implement a custom index mapping (my_mapping) in Python, BUT, I do not get the expected index mapping after the python file is run!

my_mapping = """
{
    "settings": {
        "number_of_shards": "1",
        "number_of_replicas": "1"
    },
    "mappings": {
        "properties": {
            "site": {
                "type": "completion",
            },
            "geometry": {
                "type": "geo_shape"
            }
        }
    }
}"""
result = es.index(index='my_index', document=my_mapping)

Expected Output:

{
  "mappings": {
    "_doc": {
      "properties": {
        "geometry": {
          "type": "geo_shape"
        },
        "site": {
          "type": "completion",
          "analyzer": "simple",
          "preserve_separators": true,
          "preserve_position_increments": true,
          "max_input_length": 200
        }
      }
    }
  }
}

Actual output:

{
  "mappings": {
    "_doc": {
      "properties": {
        "mappings": {
          "properties": {
            "properties": {
              "properties": {
                "geometry": { ...........

BUT! NOTE that when I instead use the following python to create the index, I DO get the expected outcome.

result = es.index(index='my_index', document=my_mapping)

Can someone please explain to me the inconsistency, and HOW to generate the expected outcome USING es.index

Answers from https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584

“The es.index is meant to index documents. Not to call the create index API.”

On the other hand, Es.indices.create Creates an index with optional settings and mappings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM