0

I'm trying to implement relevance feedback for Elastic Search (Elastic.co).

I'm aware of boosting queries, which allow for the specification of postiive and negative terms, with the idea being to discount the negative terms, while not excluding them as would be the case in a boolean must_not.

However, I'm trying to achieve tiered boosting, of both positive and negative terms.

That is, I want to take a list of binned positive and negative terms and generate a query such that there are different positive and negative boost tiers, each containing their own query terms.

something like (pseudo query):

query{
 {
 terms: [very relevant terms]
 pos_boost: 3
 }
 {
 terms: [relevant terms]
 pos_boost: 2
 }
 {
 terms: [irrelevant terms]
 neg_boost: 0.6
 }
 {
 terms: [very irrelevant terms]
 neg_boost: 0.3
}
}

My question is whether or not this can be achieved with nested boosting queries, or if I'm better off with multiple should clauses.

My concern is that I'm not sure if a boost of 0.2 in the should clause of a bool query still gives the document a positive increase in the score or not, as I want to discount the document, rather than provide any increase in score.

With boosting queries, the concern is that I can't control the degree to which positive terms are weighted.

Any help, or suggestions for other implementations, would be greatly appreciated. (What I really wanted to do was create a language model for relevant documents and use that to rank, but I don't see how that can easily be achieved in elastic.)

smck1
  • 1

3 Answers3

1

Seems that you can combine bool query and use boosting query clauses tweaking boost values.

POST so/boost/ {"text": "apple computers"}
POST so/boost/ {"text": "apple pie recipe"}
POST so/boost/ {"text": "apple tree garden"}
POST so/boost/ {"text": "apple iphone"}
POST so/boost/ {"text": "apple company"}

GET so/boost/_search
{
 "query": {
   "bool": {
     "must": [
       {
         "match": {
           "text": "apple"
         }
       }
     ], 
     "should": [
       {
         "match": {
           "text": {
             "query": "pie",
             "boost": 2
           }
         }
       },
       {
         "match": {
           "text": {
             "query": "tree",
             "boost": 2
           }
         }
       },
       {
         "match": {
           "text": {
             "query": "iphone",
             "boost": -0.5
           }
         }
       }
     ]
   }
 } 
} 
Slam
  • 8,112
  • 1
  • 36
  • 44
  • Awesome, thanks. I wasn't aware that negative boosts were possible (I had read somewhere they had to be >0). I've run that through the validator and it doesn't complain - so I'll give it a go! – smck1 Aug 14 '15 at 12:01
1

Alternately, if you want to encode your language model into your collection at index-time, you can try the approach described here: Elasticsearch: Influence scoring with custom score field in document

Community
  • 1
  • 1
Peter Dixon-Moses
  • 3,169
  • 14
  • 18
  • Aha! So there is a way to do it. I think I'll play with this with the aim of expanding on the boosting query answer. Thanks! – smck1 Aug 14 '15 at 12:01
0

To boost the elastic search document(priority based search query) based on custom/variable boost value at query time i.e. conditional boosting.

Java Coding example:

customerKeySearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(keys.type",  "xxx"));
customerTypeSearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("keys.keyValues.value", "xxxx"));                     
keyValueQuery = QueryBuilders.boolQuery().must(customerKeySearch).must(customerTypeSearch).boost(2f);

customerKeySearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(keys.type",  "xxx"));
customerTypeSearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("keys.keyValues.value", "xxxx"));                     
keyValueQuery = QueryBuilders.boolQuery().must(customerKeySearch).must(customerTypeSearch).boost(6f);

Description and search query:

elastic search has its internal score calculation technic so we need to disable this mechanism by setting disableCoord(true) property to true in java for BoleanQuery to apply custom boost effect.

Following Boolean query is running query for boosting the documents in elastic search index based on boost value.

 {
  "bool" : {
    "should" : [ {
      "bool" : {
        "must" : [ {
          "constant_score" : {
            "query" : {
              "term" : {
                "keys.type" : "XXX"
              }
            }
          }
        }, {
          "constant_score" : {
            "query" : {
              "term" : {
                "keys.keyValues.value" : "XXXX"
              }
            }
          }
        } ],
        "boost" : 2.0
      }
    }, {
      "bool" : {
        "must" : [ {
          "constant_score" : {
            "query" : {
              "term" : {
                "keys.type" : "XXX"
              }
            }
          }
        }, {
          "constant_score" : {
            "query" : {
              "term" : {
                "keys.keyValues.value" : "500072388315"
              }
            }
          }
        } ],
        "boost" : 6.0
      }
    }, {
      "bool" : {
        "must" : [ {
          "constant_score" : {
            "query" : {
              "term" : {
                "keys.type" : "XXX"
              }
            }
          }
        }, {
          "constant_score" : {
            "query" : {
              "term" : {
                "keys.keyValues.value" : "XXXXXX"
              }
            }
          }
        } ],
        "boost" : 10.0
      }
    } ],
    "disable_coord" : true
  }
}