我正在使用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)
答案 0 :(得分:1)
您可以将42
和"42"
作为数字类型,因为它仍然是数字,但它对搜索和存储此字段没有影响,但您无法提供,例如{ {1}}在任何数字字段中。