Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"boost" not working for "term" query

I'm running Elasticsearch 1.5.2 and trying the following query:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "gender": "male"
              }
            }
          ]
        }
      },
      "query": {
        "bool": {
          "must": [
            {
              "match_all": {}
            }
          ],
          "should": [
            {
              "term": {
                "top_users": 1,
                "boost": 2
              }
            }
          ]
        }
      }
    }
  }
}

Everything is fine until I add the "boost": 2 to the should -> term part. The complete query is much more complex, that's why I need to boost, but the remaining queries don't make any difference: ES returns an error 400 if a term query gets a boost argument:

QueryParsingException[[index_name] [_na] query malformed, must start with start_object]

Any suggestions?

like image 246
Sebastian Avatar asked Jul 10 '15 11:07

Sebastian


1 Answers

It should be like this:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "gender": "male"
              }
            }
          ]
        }
      },
      "query": {
        "bool": {
          "must": [
            {
              "match_all": {}
            }
          ],
          "should": [
            {
              "term": {
                "top_users": {
                  "value": "1",
                  "boost": 2
                }
              }
            }
          ]
        }
      }
    }
  }
}
like image 51
Andrei Stefan Avatar answered Oct 05 '22 17:10

Andrei Stefan