ElasticSearch在索引数据时不尊重自定义映射

时间:2018-05-25 02:29:33

标签: python elasticsearch

我正在使用ElasticSearch 6.2.4。目前正在学习它并用Python编写代码。以下是我的代码。无论我将age作为Integer还是text,它仍会接受它。

from elasticsearch import Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# index settings
settings = {
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
    },
    "mappings": {
        "members": {
            "dynamic": "strict",
            "properties": {
                "name": {
                    "type": "text"
                },
                "age": {
                    "type": "integer"
                },
            }
        }
    }
}

if not es.indices.exists('family'):
    es.indices.create(index='family', ignore=400, body=settings)
    print('Created Index')

data = {'name': 'Maaz', 'age': "4"}
result = es.index(index='family', id=2, doc_type='members', body=data)
print(result)

1 个答案:

答案 0 :(得分:1)

您可以将42"42"作为数字类型,因为它仍然是数字,但它对搜索和存储此字段没有影响,但您无法提供,例如{ {1}}在任何数字字段中。