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

标签 python elasticsearch

我正在使用 ElasticSearch 6.2.4。目前正在学习它并用Python编写代码。以下是我的代码。无论我将 age 指定为 Integertext,它仍然接受它。

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/

相关文章:

python - Elasticsearch必须具有多个条件

c# - 使用 NEST 批量插入 ElasticSearch

elasticsearch - 将精确的字符串与数组中的一个字母匹配

python - 将 TFRecords 转换回 JPEG 图像

python - Lenstra 的椭圆曲线分解问题

python - 如何在paramiko中使用scp命令

python - 如何乘以 Python Xarray 数据集?

python - 如何从 Elasticsearch 7.X.X 中获取超过 10000 条记录

linux - Elasticsearch进程内存锁定失败

python - 无法将标准输出恢复为原始状态(仅限终端)