elasticsearch - ElasticSearch 中的动态模板失败

标签 elasticsearch

我尝试创建一个简单的模板,包括一些动态模板,但我似乎无法为文档编制索引。

我得到错误:

400 {"error":"MapperParsingException[mapping [_default_]]; nested: ClassCastException[java.util.LinkedHashMap cannot be cast to java.util.List]; ","status":400}

如果我删除 JSON 的 dynaic_templates 部分,它会正常工作。

我做错了什么?

以下是 python 代码的复制:

import requests
import json

template = {
    "template": "some_index_*",
    "settings": {
        "index": {
            "number_of_replicas": "0",
            "number_of_shards": "8",

        }
    },
    "mappings": {
        "_default_": {
            "_all": {
                "enabled": False
            },
            "properties": {
                "H1": {
                    "properties": {
                        "sub1": {
                            "doc_values": True,
                            "type": "boolean",
                            "index": "not_analyzed"
                        },
                        "sub2": {
                            "index": "no",
                            "type": "string"
                        },
                    }
                }
            },
            "dynamic_templates": {
                "text_indexed_template": {
                    "match_mapping_type": "string",
                    "mapping": {
                        "index": "not_analyzed",
                        "type": "string",
                        "doc_values": True
                    },
                    "match": "*_idx"
                }
            },
            "_source": {
                "compress": False
            }
        }
    },
}

res = requests.put(
    url="http://127.0.0.1:9200/" + "_template/my_template/",
    data=json.dumps(template)
)

print res.status_code, res.content

new_doc = {
            "H1": {
                "sub1": True,
                "sub2": "testing, testing"
            }
        }

res = requests.post(
    url="http://127.0.0.1:9200/" + 'some_index_tryme/record/',
    data=json.dumps(new_doc)
)

print res.status_code, res.content

最佳答案

dynamic_templates 应该是一个元素数组,意味着被 [ ] 包围。所以,你的应该是这样的:

  "dynamic_templates": [
    {
      "text_indexed_template": {
        "match_mapping_type": "string",
        "mapping": {
          "index": "not_analyzed",
          "type": "string",
          "doc_values": true
        },
        "match": "*_idx"
      }
    }
  ]

关于elasticsearch - ElasticSearch 中的动态模板失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31286483/

相关文章:

elasticsearch - 如何在Elasticsearch中获取返回结果的最大日期值

java - 通过 JAVA API 将映射放入 ElasticSearch

c# - Nest Elasticsearch 的文档术语频率

elasticsearch - 查询elasticsearch —获取每个节点,每个主机的文档数

elasticsearch - 当结果少于 scrollSize 设置时,Scroll SearchResponse 不可迭代

elasticsearch - 使用 Elasticsearch 地理功能查找按时间排序的最常见位置

elasticsearch - 如何在ElasticSearch中获取倒排索引的大小

elasticsearch - ElasticSearch-筛选,分组并计算每个组的结果

elasticsearch - 使用ReactiveSearch进行AND查询

datetime - 具有日期格式的索引映射,使用curl引发解析异常