Search nested objects using wildcard paths?

Hi. need help with querying 2 level deep nested objects using wildcard for paths
my mapping looks like this:

{
   "article": {
      "dynamic_templates": [
         {
            "en": {
               "path_match": "versions.*en",
               "mapping": {
                  "type": "nested",
                  "properties": {
                     "title": {
                        "type": "string",
                        "analyzer": "english"
                     },
                     "content": {
                        "type": "string",
                        "analyzer": "english"
                     }
                  }
               }
            }
         },
         {
            "standard": {
               "path_match": "versions.*",
               "mapping": {
                  "type": "nested",
                  "properties": {
                     "title": {
                        "type": "string",
                        "analyzer": "standard"
                     },
                     "content": {
                        "type": "string",
                        "analyzer": "standard"
                     }
                  }
               }
            }
         }
      ],
      "properties": {
         "source": {
            "type": "string",
            "index": "not_analyzed"
         },
         "external_id": {
            "type": "string",
            "index": "not_analyzed"
         }
      }
   }
}

I have nested field called versions and it contains many article versions like this:

{
   "source": "forbes",
   "external_id": "1234",
   "versions": {
      "en": {
         "title": "title en",
         "content": "content en"
      },
      "localized_en": {
         "title": "title localized en",
         "content": "content localized en"
      },
      "fr": {
         "title": "title fr",
         "content": "content fr"
      }
   }
}

query like this is working as expected

{
   "query": {
      "nested": {
         "path": "versions",
         "query": {
            "nested": {
               "path": "versions.en",
               "query": {
                  "match": {
                     "versions.en.content": "content"
                  }
               }
            }
         }
      }
   }
}

I was trying to use multi_match query , but with no luck:

{
   "query": {
      "nested": {
         "path": "versions",
         "query": {
            "multi_match": {
               "query": "content",
               "fields": [
                  "versions.*.content"
               ]
            }
         }
      }
   }
}

Is there any way to do this?

Personally I would have modelled this slightly differently by moving the language information into the version object itself.

That being said, the following thread might contain some more background information for you:

http://elasticsearch-users.115913.n3.nabble.com/Search-nested-quot-nested-objects-quot-using-quot-wildcard-paths-quot-td4027268.html

Hope this helps,
Isabel

thanks for your reploy @mainec. You mean somethins like this?

{
   "source": "forbes",
   "external_id": "1234",
    "version_en": {
       "title": "title en",
       "content": "content en"
    },
    "version_localized_en": {
       "title": "title localized en",
       "content": "content localized en"
    },
    "version_new_en": {
       "title": "title new en",
       "content": "content new en"
    },
    "version_fr": {
       "title": "title fr",
       "content": "content fr"
    }
}

but question is still the same, will be I able to query all nested objects using some kind of wildcard route? I mean wildcard like this "version_*.title":

Sorry for being not clear enough. What I meant was to do something like this:

{
    "lang": "fr",
    " title": "title fr",
    "content": "content fr"
}

But I can't create dynamic template matcher based on fields value. I need to be able to use different analyzers for different languages

Hello @syzspectroom,

Did you ever find a solution for this issue? We have a similar use case where we will have an object with multiple languages that require different text analyzers.

{
  "keywords": {
    "en": ["cat"]
    "es": ["gato"]
  }
}

We would like to compose a query like this so we would get a hit on English or Spanish terms.

QueryBuilders.boolQuery().filter(QueryBuilders.matchQuery("content.keywords.*", "cat"));

Thanks,
Drew