Boosting fields for multi match without specifying complete field list in query

I am trying to boost fields using multi match query without specifying complete field list but I cannot find out how to do it. I am searching through multiple indices on all fields, which I don't know at the run time, but I know which are the important ones.

For example lets have an index "bank" with fields: "name", "address" and index "customer" with fields: "name", "gender", "age". I need to search across both indexes through all fields with the boosting on field "name".

I know how to search across all fields:
//GET bank,customer/_search
//{
// "query":{
// "multi_match":{
// "query":"al"
// }
// }
//}

But what if I want to boost name field? How to write it without specifying all fields? Something like this:

//GET bank,customer/_search
// {
// "query":{
// "multi_match":{
// "query":"al",
// "fields":[ "name^5", "*" ]
// }
// }
//}

Hi,
in general, I don't think it's a good idea to run a multi_match query on all fields. This is discouraged in many ways (e.g., check the explicit warning in the documentation page). Also, looking at your use case, I don't see what benefit would bring to boost the name (a string) and still look into the age field (an integer). I would recommend you to narrow down the number of fields considered in your multi_match query.

Thank you for your answer. I will probably narrow the fields, but general though is the same - is it possible? Sometimes I need to search among number fields as well (for example to search "26", to see all records related to this number - it could be age, it could be in bank name, or in some other field e.g. some description, but if it is part of the name it should be higher in results). I am using NEST, so in the end, I could probably generate list of all fields programmatically using reflection on my models, but I would rather not :slight_smile: I know that there is general warning, but at the moment it is not the case, because I am operating on relatively small data set with thousands records and tens of fields in total among all indices.

I see. Well, if you don't specify the fields parameter, then the multi_match will look into every fields. But since you want to give a special boost to one particular field, you could do something like:

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "al",
            "fields": "name^5"
          }
        },
        {
          "multi_match": {
            "query": "al"
          }
        }
      ]
    }
  }
}

Still, much better to narrow down the number of fields to look into - especially because you want to run this query on multiple indices per time :slight_smile:

That is exactly what I do have at the moment :slight_smile: I could specify the fields, but since my database is currently serving only for text search (no aggregations or anything else), I am holding only data I want to search through, so in the end, I would probably need to name all fields as well.

I was asking because of this paragraph in documentation:

If no fields are provided, the multi_match query defaults to the index.query.default_field index settings, which in turn defaults to * . * extracts all fields in the mapping that are eligible to term queries and filters the metadata fields. All extracted fields are then combined to build a query.

So I was thinking if there is some shortcut to somehow specify '*' in fields as well.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.