【问题标题】:Creating analyzed and not_analyzed index on all fields in Elasticsearch在 Elasticsearch 中的所有字段上创建已分析和未分析的索引
【发布时间】:2015-08-18 13:47:47
【问题描述】:

我对 Elasticsearch 很陌生。我需要使用“已分析”和“未分析”索引创建所有字符串字段。我已经能够为 1 或 2 个字段执行此操作,但如果我的文档中有 50 个字段,我该怎么做?我使用以下代码在几个字段上创建了这样的索引:

mapping = {
    "my_type": {
        "properties": {
            "random_num": {"type": "string"},
            "category": { "type":"multi_field", "fields":{ "category":{ "type":"string", "index":"analyzed" },"untouched":{ "type":"string", "index":"not_analyzed" } } },
            "url": {"type": "string"},
            "id": {"type": "string"},
            "desc": { "type":"multi_field", "fields":{ "desc":{ "type":"string", "index":"analyzed" },"untouched":{ "type":"string", "index":"not_analyzed" } } }
        }
    }
}

如果有人能帮我解决这个问题,我将不胜感激。谢谢!

【问题讨论】:

    标签: python indexing elasticsearch mapping


    【解决方案1】:

    您可以浏览文档here。 使用动态索引模板,您可以添加如下规则并实现相同的目标。 在下面的示例中,我启用了一个名为 raw 的附加字段,仅当大小小于 256 时才会被 not_analyzed。

    {
      "mappings": {
        "my_type": {
          "dynamic_templates": [
            {
              "string_fields": {
                "mapping": {
                  "type": "string",
                  "fields": {
                    "raw": {
                      "index": "not_analyzed",
                      "ignore_above": 256,
                      "type": "string"
                    }
                  }
                },
                "match_mapping_type": "string",
                "match": "*"
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多