elasticsearch - 为字段的所有子字段设置 'index'属性

标签 elasticsearch pyes

在尝试添加术语方面时,我遇到了以下问题:术语被标记为单独的单词。例如,如果属性(字段)Kind具有值medium kind of shirtlarge kind of shirt,则这些术语变为-mediumlargekindofshirt

为了解决这个问题,建议我更改映射,以便为每个属性字段包括"index": "not_analyzed"。问题是映射是动态生成的,例如-:

"attributes": {
   "properties": {
      "kind": {
         "type": "string"
      },
      "color": {
         "type": "string"
      },
      "size": {
         "type": "string"
      }
   }
}

简单地将"not_analyzed"中的"attributes"位置1并不会。有没有办法为attributes字段内的每个子字段设置索引属性?

最佳答案

感谢Andrei的评论,我能够弄清楚如何应用设置。

我在映射中添加了一个dynamic_templates部分,如下所示:

"dynamic_templates": [
    {
        "string_template": {
            "path_match": "attributes.*",
            "match_mapping_type": "string",
            "mapping": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
]

这可以解决问题,现在每个"string"类型的子字段都有自己的"index"设置为"not_analyzed"。这些条款不再标记化。

关于elasticsearch - 为字段的所有子字段设置 'index'属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27937630/

相关文章:

python - Elastic Search没有可用的服务器,列表索引超出范围

python - 如何使 pyes 搜索方法返回找到的文件的键?

java - 线程中出现异常 "main"java.lang.IllegalArgumentException : java. lang.Object 不是索引实体或索引实体的子类

arrays - Elasticsearch - 过滤其中(嵌套数组之一)和(所有嵌套数组)

elasticsearch - 在 Elasticsearch 中过滤出分支

python - 使用 pyes 构建 ElasticSearch 搜索

elasticsearch - 插入时防止在Elasticsearch对象数组中重复

mongodb - 同步elasticsearch和mongodb

elasticsearch - 提高ElasticSearch的性能