Elasticsearch - 动态字段模板映射

标签 elasticsearch

例如,我想为书籍和文件制作映射。这些书籍和文件有共同的标题字段,但之后是不同的字段。因此,我制作了动态模板(进行此映射的主要原因是让某些字符串字段设置为关键字,而不是文本)。

   PUT my_index
    {
        "mappings" : {
            "my_type" : {
                "properties" : {
                    "title" : {
                        "type" : "keyword"
                    },
                    "props" : {
                        "dynamic" : true,
                        "dynamic_templates": [
                        {
                          "strings": {
                            "match_mapping_type": "string",
                            "mapping": {
                              "type": "keyword"
                            }
                          }
                        }
                      ]
                    }
                }
            }
        }
    }

我这样做了,但随之而来的错误。

"reason": "Failed to parse mapping [my_type]: No type specified for field [props]",

对此有什么想法吗?

最佳答案

动态模板是类型的根,请参阅 the link

你应该有这样的东西

{
  "mappings": {
    "my_type": {
      "properties": {
        "title": {
          "type": "keyword"
        }
      },
      "dynamic_templates": [
        {
          "strings": {
            "path_match":   "props.*",
            "match_mapping_type": "string",
            "mapping": {
              "type": "keyword"
            }
          }
        }
      ]
    }
  }
}

关于Elasticsearch - 动态字段模板映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43646701/

相关文章:

elasticsearch - NEST:更新源过滤器

elasticsearch - kibana可视化范围查询不起作用

c# - Elasticsearch.net NEST Bool查询未生成预期的请求

elasticsearch - PHP 客户端上用于 elasticsearch 的嵌套语法的 inner_hits 似乎不起作用

node.js - 刷新索引映射并减少总字段数

c# - C# Elasticsearch 与嵌套的精确文本匹配

spring - 将Elasticsearch从5.6.8更新到6.2.3

Elasticsearch _query 与 _search

elasticsearch - 使用应该的 Elasticsearch 查询不起作用

spring - 如何在Elasticsearch中获取时间戳值?