Elasticsearch - 将动态字段索引更改为not_analyzed

时间:2014-09-19 13:57:53

标签: elasticsearch

我在我的模型中有一个带有动态字段的rails应用程序。这些字段可以有一些特殊的字符(例如:'/'),我想要在这些字段上使用。 我不想更改动态映射的默认值,但我希望它们不被分析。

这是我的映射:

GET /items/_mapping

{
 .
 .
  "dynamic_field_1": {
    "type": "string"
  },
 .
 .
}

有没有办法更新映射到这个?

GET /items/_mapping

{
 .
 .
  "dynamic_field_1": {
    "type": "string",
    "index": "not_analyzed"
  },
 .
 .
}

最终回到'分析':)

1 个答案:

答案 0 :(得分:0)

创建索引时需要使用这样的动态映射:

    POST /items/_mapping
    {
      "mappings": {
        "_default_": {
          "dynamic_templates": [
            {
              "string_template": {
                "mapping": {
                  "index": "not_analyzed",
                  "type": "string"
                },
                "match_mapping_type": "string",
                "match": "*"
              }
            }
          ]
        }
      }
    }

您还可以在那里指定非动态字段。