简体   繁体   中英

index a @MultiField spring-data-elasticsearch. Internationalization purposes

I´m trying to index a multiField String attribute ("prueba") for multilingual purposes. My mapping is working with annotations

@MultiField(
      mainField = @Field(type = FieldType.String, store = true),
      otherFields = {
              @NestedField(dotSuffix = "cat", type = FieldType.String, store = true, indexAnalyzer = "catalan", searchAnalyzer = "catalan" ),
              @NestedField(dotSuffix = "ba", type = FieldType.String, store = true, indexAnalyzer = "basque", searchAnalyzer = "basque"),
              @NestedField(dotSuffix = "gal", type = FieldType.String, store = true, indexAnalyzer = "galician", searchAnalyzer = "galician"),
              @NestedField(dotSuffix = "en", type = FieldType.String, store = true, indexAnalyzer = "english", searchAnalyzer = "english")}
       )
protected String prueba;

The result mapping is :

,
           "prueba": {
              "type": "string",
              "store": true,
              "fields": {
                 "prueba.ba": {
                    "type": "string",
                    "store": true,
                    "analyzer": "basque"
                 },
                 "prueba.cat": {
                    "type": "string",
                    "store": true,
                    "analyzer": "catalan"
                 },
                 "prueba.en": {
                    "type": "string",
                    "store": true,
                    "analyzer": "english"
                 },
                 "prueba.gal": {
                    "type": "string",
                    "store": true,
                    "analyzer": "galician"
                 }
              }
           },

So, I index my object but the result is only...`

IndexQuery query = new IndexQuery();
query.setObject(itemTransparencia);
query.setType(subportal);

String id = this.elasticsearchOperations.index(query);

GET /item_transparencia/432/_search

{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "item_transparencia",
            "_type": "432",
            "_id": "AVTxEfvBhgYXtMQTaKx1",
            "_score": 1,
            "_source": {
               "subportal": "432",
               "titulo": null,
               "prueba": "prueba la tarta de mi casa",
               "subTitulo": null,
               "descripcion": null,
               "fechaIndexado": "2016-05-

I only get "prueba": "prueba la tarta de mi casa" .

-Could anybody help me to understand how can I index or get the nested fields from field "prueba"? -Does indexAnalyzer = "catalan", searchAnalyzer = "catalan" help me to index automatically to another lenguage?

thank so much!

The multi-fields prueba.ba , prueba.cat , prueba.en , prueba.gal have been indexed but you won't see them in your source document.

You can now reference them directly in your queries (the analyzer declared in the mapping will be used as expected) and you'll get the results you expect. For instance, the following query should return you the document with id AVTxEfvBhgYXtMQTaKx1 .

{
   "query": {
      "match": {
         "prueba.ba": "prueba"
      }
   }
}

However, just note that setting a language analyzer on a field won't translate the field's content into that analyzer's language, you need to do that yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM