0

我将有一个包含多个字段的文档。让我们说'title','meta1','meta2','full_body'。我想以几种不同的方式对它们中的每一个进行索引(原始、不带停用词的词干、带状疱疹、同义词等)。因此,我将拥有以下字段:title.stemmingtitle.shinglesmeta1.stemmingmeta1.shingles

我必须复制粘贴每个字段的映射定义吗?或者是否可以为所有索引/分析方式创建一个定义,然后仅将其应用于 4 个顶级字段中的每一个?如果是这样,如何?

  mappings: 
    my_type: 
      properties: 
        title: 
          type: string
          fields: 
            shingles: 
              type: string
              analyzer: my_shingle_analyzer
            stemming:
              type: string
              analyzer: my_stemming_analyzer
        meta1:
           ...                   <-- do i have to repeat everything here?
        meta2:
           ...                   <-- and here?
        full_body:
           ...                   <-- and here?
4

1 回答 1

2

在您的情况下,您可以使用带有设置的动态模板match_mapping_type,以便您可以将相同的设置应用于所有字符串字段:

{
  "mappings": {
    "my_type": {
      "dynamic_templates": [
        {
          "strings": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "fields": {
                "shingles": {
                  "type": "string",
                  "analyzer": "my_shingle_analyzer"
                },
                "stemming": {
                  "type": "string",
                  "analyzer": "my_stemming_analyzer"
                }
                , ... other sub-fields and analyzers
              }
            }
          }
        }
      ]
    }
  }
}

因此,每当您索引一个字符串字段时,它的映射将根据定义的模板创建。您还可以使用该match设置将映射限制为仅特定字段名称。

于 2016-01-18T12:00:32.437 回答