在Elasticsearch中为所有字段创建已分析和未分析的索引

2024-09-29 19:26:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Elasticsearch很陌生。我需要用“analysed”和“not_analysed”索引创建所有字符串字段。我已经能够为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" } } }
        }
    }
}

如果有人能帮我解决这个问题,我会非常感激的。谢谢!在


Tags: 字符串fieldfieldsstringindextypenotelasticsearch
1条回答
网友
1楼 · 发布于 2024-09-29 19:26:38

您可以浏览文档here。 使用动态索引模板,您可以添加如下规则和acienve相同的规则。 在下面的示例中,我启用了一个名为raw的附加字段,该字段仅在大小小于256的情况下启用,该字段不会被分析。在

{
  "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": "*"
          }
        }
      ]
    }
  }
}

相关问题 更多 >

    热门问题