Tibor Nagy
Tibor Nagy

Reputation: 1236

How to use elasticsearch indexes with different weight

I've created more elasticsearch indexes for different type of information in our system. Mainly they are used individually to look for elements in a particular index. However we have a general search on our home page, where the user can search in all indexes. E.g. the following search will be used:

curl -XGET 'localhost:9200/my-index-%2A/_doc/_search?pretty' -H 'Content-Type: application/json' -d'
{                         
  "size":25,              
  "query":{               
    "bool":{              
      "must":[            
        {                 
          "term":{"languageCode":"de"}
        },                
        {                 
          "bool":{        
            "should":[
              {
                "simple_query_string":{
                  "query":"search-term",
                  "fields":[
                    "title_*.language^50",
                    "description_*.language^10",
                    "content_*.language^1"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}'

I'm using in this search many indexes with wildcard (my-index-*/_doc/_search). It works absolutely correct, but my problem is, that I want that one of the indexes generates less score as the others. Is there any possibility to give less weight to an index in a multi-index query?

Upvotes: 0

Views: 1170

Answers (1)

Stefano Branco
Stefano Branco

Reputation: 658

Yes, you can indeed apply an index boost

GET /_search
{
    "indices_boost" : [
        { "my-index-do-not-want" : 0.5 }
    ]
}

In addition, depending on your use case you might want to consider turning on dfs_query_then_fetch for that query, as mentioned [here].(elasticsearch scoring on multiple indexes) That way, your scores should be more comparable between indexes.

Upvotes: 1

Related Questions