简体   繁体   English

Python Elasticsearch 创建索引映射

[英]Python Elasticsearch create index mapping

I am trying to create a ES index with custom mapping with elasticsearch python to increase the size of text in each document:我正在尝试使用 elasticsearch python 创建具有自定义映射的 ES 索引,以增加每个文档中文本的大小:

mapping = {"mapping":{
           "properties":{
             "Apple":{"type":"text","ignore_above":1000},
             "Mango":{"type":"text","ignore_above":1000}
           }
          }}

Creation:创建:

from elasticsearch import Elasticsearch
es1 = Elasticsearch([{"host":"localhost","port":9200}])
es1.indices.create(index="hello",body=mapping)

Error:错误:

RequestError: RequestError(400, 'mapper_parsing_exception', 'Mapping definition for [Apple] has unsupported parameters: [ignore_above : 10000]') 

But I checked the elasticsearch website on how to increase the text length limit and ignore_above was the option given there.但是我查看了 elasticsearch 网站关于如何增加文本长度限制,并且ignore_above是那里给出的选项。 https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-above.html https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-above.html

Any suggestions on how to rectify this will be great.任何关于如何纠正这个问题的建议都会很棒。

The ignore_above setting is only for keyword types not text , so just change your mapping to this and it will work: ignore_above设置仅适用于keyword类型而不是text ,因此只需将映射更改为此即可:

mapping = {"mapping":{
       "properties":{
         "Apple":{"type":"text"},
         "Mango":{"type":"text"}
       }
      }}

If you absolutely need to be able to specify ignore_above then you need to change the type to keyword , like this:如果您绝对需要能够指定ignore_above那么您需要将类型更改为keyword ,如下所示:

mapping = {"mapping":{
       "properties":{
         "Apple":{"type":"keyword","ignore_above":1000},
         "Mango":{"type":"keyword","ignore_above":1000}
       }
      }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Elasticsearch:“es.index”和“es.indices.create”之间的索引映射不一致 - Python Elasticsearch : Index mapping inconsistencies between ‘es.index’ and ‘es.indices.create’ 使用Python API通过映射将CSV加载到Elasticsearch索引 - Loading CSV to elasticsearch index with mapping using Python API 使用 Python 客户端通过映射将不规则 json 加载到 Elasticsearch 索引中 - Loading irregular json into Elasticsearch index with mapping using Python client 如何使用 Python 在 ElasticSearch 中创建嵌套索引? - how to create a nested index in ElasticSearch with Python? 如何创建嵌套字典以便通过 Python 为 Elasticsearch 创建映射? - How to create nested dicts in order to create mapping for Elasticsearch by Python? 使用映射创建新的ElasticSearch索引 - Creating a new ElasticSearch index with mapping Elasticsearch为嵌套数组创建映射 - Elasticsearch create a mapping for nested array Python requests.post 不会强制 Elasticsearch 创建缺失的索引 - Python requests.post does not force Elasticsearch to create missing index Python 3:如何使用 json 变量自动创建索引并发送到 Elasticsearch? - Python 3: How to automatically create index with json variable and send to Elasticsearch? python elasticsearch客户端在创建索引期间设置映射 - python elasticsearch client set mappings during create index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM