Query on fieldname with wildcard?


#1

Hi,

In order to support multi-lingual documents, we stored them with the suffix of the language code, such as:
{
"description_EN": "My Description",
"description_FR": "Ma Description"
}

We do not know in advance, in which language(s) documents are generated and we support up to 24 languages. Mappings for the 24 languages were created.

Therefore my question:

How can I run a query against all documents, not knowing the "field name" suffix?

I would need something like;

..."wildcard": {
"description_*.keyword": {
"wildcard": "a"
}
}

but this does not work...

Any help would be more than welcome.

Many thanks in advance,


(Byron Voorbach) #2

One way which could work is using the query_string / simple_query_string query.

{
  "query": {
    "query_string": {
      "query": "a*",
      "fields": [
          "description_*"
        ]
    }
  }
}

They allow wildcards in both field names and query terms


#3

thank you so much. It works !! :slight_smile:


(Byron Voorbach) #4

Cool! :smiley: happy coding