【问题标题】:How to specify index.mapping.ignore_malformed in elasticsearch python lowlevel client?如何在 elasticsearch python 低级客户端中指定 index.mapping.ignore_malformed?
【发布时间】:2019-11-13 20:00:26
【问题描述】:
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.create(index='report', ignore=400)
es_reponse = es.index(index='reports',doc_type='text',body=report_json)

我来了

RequestError(400, 'illegal_argument_exception', 'mapper [table.rows.endDate] 不同类型,current_type [日期], 合并类型 [文本]')

这个错误,可以通过设置 index.mapping.ignore_malformed : false 来解决,但是我不知道在代码中的哪里指定这个? 我正在使用elasticsearch 7.0.5

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    您可以在Python 中使用此参数创建索引:

    from elasticsearch_dsl import Index
    from elasticsearch import Elasticsearch
    
    es=Elasticsearch(['ES_URL:ES_PORT'])
    
    
    index = Index('my_index', es)
    index.settings(
         number_of_shards=6,
         number_of_replicas=2,
         index={'mapping':{'ignore_malformed':False}}) //or True
    index.create()
    

    这就是Elasticsearch 上的样子:

    [root@host]$ curl -XGET ES_URL:ES_PORT/my_index/_settings?pretty
    {
      "my_index" : {
        "settings" : {
          "index" : {
            "mapping" : {
              "ignore_malformed" : "false"
            },
            "number_of_shards" : "6",
            "provided_name" : "my_index",
            "creation_date" : "1573646292390",
            "number_of_replicas" : "2",
            "uuid" : "e__BuX-KSSeoR2LXQXaWkA",
            "version" : {
              "created" : "6020499"
            }
          }
        }
      }
    }
    

    【讨论】:

    • 我想直接在elasticsearch中索引来自rest api的json对象。我不能使用 elasticsearch_dsl,因为我没有在模型中存储数据。我应该如何在索引中添加直接来自 api (json) 的文档?
    • 我们可以直接在elasticsearch中索引json object吗? @dejanmarich
    • 可以索引 json 对象,因为 Elasticsearch 将文档存储为 json 对象
    • @AbdulSamad - 忽略格式错误是在索引映射中定义的,与插入数据操作无关,您只需使用此设置创建索引,然后执行标准插入操作..
    • 感谢伙伴的帮助。我刚刚开始使用 python 进行弹性搜索,如果您分享与我的东西相关的任何示例/链接,我会很高兴。谢谢
    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多