我正在使用 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)
最佳答案
您可以将 42
和 "42"
作为数字类型,因为它仍然是数字,并且对搜索和存储该字段没有影响,但您不能例如,在任何数字字段中输入“42a”
。
关于python - ElasticSearch 在索引数据时不尊重自定义映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50520653/