1

I am trying to boost certain indices in my elastic search query. Right now, my query is looking like this.

var query = {
    "query": {
        "query_string": {
            "fields": ["FirstName", "LastName"],
            "query": "Hank Hill",
            "default_operator": "AND"
        }
    }
};

var boosted_indices = {
    "index_A" : 1.0,
    "index_B" : 1.0,
    "index_C" : 10.0
};

if (boosted_indices) {
    query["indices_boost"] = boosted_indices;
}

// stringify and send query in an http.get request

I know that my query without boosting any indices works as I expect. However, I am still getting a lot of results from "index_A" in my query results, rather than the heavily boosted index_C. I know that there should be a similar number of matching results in A and C, so the issue must be that I am not boosting the query correctly.

Did I set up my query JSON incorrectly? On the tutorial I linked, it did not give much context.

One other thing I noticed.. the "_score" field for the returned documents... all of them are set to null. Might this have something to do with my documents not being boosted according to the index they came from?

Zack
  • 13,454
  • 24
  • 75
  • 113
  • according to the comment in code looks like you are using `get` request. Could you try `post` request ? – keety Oct 26 '15 at 17:09

1 Answers1

1

I hope you are not using the sort parameter in query. This could be the reason that _score is null and you are not getting expected results.

Does this help?

ChintanShah25
  • 12,366
  • 3
  • 43
  • 44
  • This did appear to work, I was using "&sort=_id:asc" as a part of my query. I am hoping that this will not have residual effects elsewhere. But you did answer my question. Thanks! – Zack Oct 26 '15 at 20:05
  • why would sorting do anything to effect the score? – Zack Oct 26 '15 at 20:07
  • I'm in the unfortunate position of really needing that sort parameter present... I have a search results page that does not return a consistent set of results for a given url otherwise. The query is extracted from the url and the results are displayed on the page.. I need them to be the same every time, and without the sort param, the set of results varies. – Zack Oct 26 '15 at 20:12
  • 1
    you can also sort on `_score`. This will help you understand why score is null when you do sort. https://github.com/elastic/elasticsearch-php/issues/48 . so rather than doing `sort=_id:asc`, you can do `sort=_score:desc`. I hope this helps @Zack – ChintanShah25 Oct 26 '15 at 20:29