0

I have this analyzer:

{
  "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"
        }
      }
    }
  }
}

I apply it on this field:

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

And here is the Description class:

public class Description {

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

This is the resulting Elasticsearch mapping for this field:

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

Like you can see, the anlyzer is not applied at all. It works well with string fields, but I have a hard time doing it with Object types. Any ideas?
Thanks!

EDIT: I tried to use a dynamic mapping:

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

But I have this error:

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

Why do I get this error?

Anna
  • 839
  • 2
  • 17
  • 33
  • You cannot apply an analyzer on object fields, you need to explicitly add it to all the string fields you need. – Val Sep 27 '17 at 09:37
  • How can I do in this case? it's a map. – Anna Sep 27 '17 at 09:43
  • Have you tried to put the analyzer on the descriptions field directly? – Val Sep 27 '17 at 09:48
  • Yes, I tried to apply it directly on the map and it throws me this error: `Mapping definition for [localizedDescriptions] has unsupported parameters: [analyzer : word_join_analyzer]` – Anna Sep 27 '17 at 09:58
  • Will you always have the three language fields in that map? – Val Sep 27 '17 at 10:38
  • Yes I will always have the three. But later I will have much more languages.... – Anna Sep 27 '17 at 11:25
  • I would remove that map and add one String property per language with the analyzer. Later on, you are free to more languages by adding new fields. – Val Sep 27 '17 at 11:36
  • Or maybe I need a [dynamic mapping](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/dynamic-mapping.html)? – Anna Sep 27 '17 at 12:04
  • Yes, you can do it using this technique: https://stackoverflow.com/questions/38550382/setting-annotation-for-elasticsearch-is-ignored-in-spring-boot – Val Sep 27 '17 at 12:05
  • @Val: thanks for the link, but I don't see what I should do... It doesn't seem dynamic. – Anna Sep 27 '17 at 12:13
  • 1
    The idea is to put your settings and mappings in resource files and then to configure a dynamic mapping (with `"path_match": "localizedDescriptions.*"`) inside your mappings.file – Val Sep 27 '17 at 12:14
  • @Val: Thanks for the hint! I think it may resolve my problem, if I manage to use it well ^^ – Anna Sep 27 '17 at 13:37

1 Answers1

0

Finaly solved this. This is the correct mapping:

{
  "cake": {
    "dynamic_templates": [
      {
        "localized_descriptions": {
          "path_match":   "description.localizedDescriptions.*",
          "mapping": {
            "type": "string",
            "analyzer": "word_join_analyzer"
          }
        }
      }
    ]
  }
}
Anna
  • 839
  • 2
  • 17
  • 33