Sebastian
Sebastian

Reputation: 2550

"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?

Upvotes: 6

Views: 2551

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

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
                }
              }
            }
          ]
        }
      }
    }
  }
}

Upvotes: 8

Related Questions