在对象字段上应用分析器

时间:2017-09-27 09:26:18

标签: elasticsearch spring-data-elasticsearch

我有这个分析仪:

{
  "index": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "word_joiner": {
          "type": "word_delimiter",
          "catenate_all": true,
          "preserve_original": true
        }
      },
      "analyzer": {
        "word_join_analyzer": {
          "type": "custom",
          "filter": [
            "word_joiner"
          ],
          "tokenizer": "keyword"
        }
      }
    }
  }
}

我将它应用于此字段:

@Field(type = FieldType.Object, analyzer = "word_join_analyzer")
private Description description;

这是Description类:

public class Description {

       @JsonProperty("localizedDescriptions")
       private Map<String, String> descriptions = new HashMap<>();
}

这是此字段的结果Elasticsearch映射:

{  
   "description":{  
      "properties":{  
         "localizedDescriptions":{  
            "properties":{  
               "en":{  
                  "type":"string"
               },
               "fr":{  
                  "type":"string"
               },
               "it":{  
                  "type":"string"
               }
            }
         }
      }
   }
}

您可以看到,根本没有应用分析仪。它适用于字符串字段,但我很难用Object类型完成它。任何想法?
谢谢!

编辑:我尝试使用动态映射:

{
  "iam":{
    "properties":{
      "dynamic_templates":[
        {
          "localized_strings_values":{
            "path_match":"description.localizedDescriptions.*",
            "mapping":{
              "type":"string",
              "analyzer":"word_join_analyzer"
            }
          }
        }
      ]
    }
  }
}

但我有这个错误:

Expected map for property [fields] on field [dynamic_templates] but got a class java.lang.String

为什么我会收到此错误?

1 个答案:

答案 0 :(得分:0)

最终解决了这个问题。这是正确的映射:

{
  "cake": {
    "dynamic_templates": [
      {
        "localized_descriptions": {
          "path_match":   "description.localizedDescriptions.*",
          "mapping": {
            "type": "string",
            "analyzer": "word_join_analyzer"
          }
        }
      }
    ]
  }
}