elasticsearch,Python,elasticsearch" /> elasticsearch,Python,elasticsearch" />

Python 索引数据时,ElasticSearch不考虑自定义映射

Python 索引数据时,ElasticSearch不考虑自定义映射,python,elasticsearch,Python,elasticsearch,我正在使用ElasticSearch 6.2.4。目前正在学习它并用Python编写代码。下面是我的代码。无论我将年龄指定为整数或文本,它仍然接受它 from elasticsearch import Elasticsearch es = Elasticsearch([{'host': 'localhost', 'port': 9200}]) # index settings settings = { "settings": { "number_of_shards": 1

我正在使用ElasticSearch 6.2.4。目前正在学习它并用Python编写代码。下面是我的代码。无论我将
年龄
指定为
整数
文本
,它仍然接受它

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)

您可以将
42
“42”
作为数字类型,因为它仍然是数字,并且对搜索和存储此字段没有影响,但您不能在任何数字字段中给出,例如,
“42a”

。没想到它会把它解析成一个数值。