首页 > 解决方案 > ES 索引与 python - 结合正常的映射设置,包括。index.mapping.ignore_malformed

问题描述

我在尝试将 ignore_malformed 添加到我的索引设置时需要帮助。

我有:

from elasticsearch import Elasticsearch
es = Elasticsearch(
  [{'host': 'localhost', 'port': 9200}])

index_name = 'product'

settings = {
"settings": {
    "index.refresh_interval" : "1s",
    "index.mapping.total_fields.limit": 10000,
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
"mappings": {
  "properties": {
        "location": {
          "type": "geo_point"
        }
      },
    "dynamic_templates": [
      {
        "strings_as_keywords": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    ]
  }
}

es.indices.create(index=index_name, body=settings)

如果我尝试添加“index.mapping.ignore_malformed”:true,我得到: NameError:name 'true' is not defined

通过以下操作,我可以执行此设置,但在索引时我需要同时执行这两个设置:

from elasticsearch import Elasticsearch
# conntect es
es = Elasticsearch(
  [{'host': 'localhost', 'port': 9200}])
from elasticsearch_dsl import Index
index_name = 'product'
index = Index(index_name, es)
index.settings(
        index={'mapping':{'ignore_malformed':True}}
    )
index.create()

在 Kibana 的编辑设置下,我当前的索引规格是:

{
  "index.blocks.read_only_allow_delete": "false",
  "index.priority": "1",
  "index.query.default_field": [
    "*"
  ],
  "index.write.wait_for_active_shards": "1",
  "index.mapping.total_fields.limit": "10000",
  "index.refresh_interval": "1s",
  "index.number_of_replicas": "0"
}

在创建索引时如何结合上述内容以获得:

{
  "index.blocks.read_only_allow_delete": "false",
  "index.priority": "1",
  "index.query.default_field": [
    "*"
  ],
  "index.write.wait_for_active_shards": "1",
  "index.mapping.total_fields.limit": "10000",
  "index.refresh_interval": "1s",
  "index.mapping.ignore_malformed": "true",
  "index.number_of_replicas": "0"
}

另外:也无法通过在 Kibana Result = Bad Request 中编辑来添加此字符串(为什么!?)

参考: Elasticsearch 日期字段中的空字符串?

通过 ElasticSearch DSL python 包装器创建索引时,如何在索引级别设置 ignore_malformed?

感谢您的帮助问候

标签: pythonelasticsearchmappingsettings

解决方案


哦,是的,错字错误...我重新设置了设置,现在它可以工作了,即使在现场级别:)

settings = {
"settings": {
    "index.refresh_interval" : "1s",
    "index.mapping.total_fields.limit": 10000,
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "index.mapping.ignore_malformed": "true"
  },
"mappings": {
  "properties": {
        "location": {
          "type": "geo_point"
        },
        "Date":{
          "type": "date",
          #"ignore_malformed": "true"
        }
      },
    "dynamic_templates": [
      {
        "strings_as_keywords": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    ]
  }
}

推荐阅读