1

I want to search documents which match at least two key words using terms query like this:

{
  "query": {
     "terms": {
        "title": ["java","编程","思想"],
        "minimum_match": 2
    }
  },
  "highlight": {
    "fields": {
       "title": {}
    }
  }
}

It returns "terms query does not support minimum_match".What's wrong with my query?

1 Answer 1

2

The correct name was minimum_should_match and that setting has been deprecated in ES 2.0.

What you can do instead is to use a bool/should query with three term queries and the minimum_should_match setting for bool/should queries:

{
  "query": {
    "bool": {
      "minimum_should_match": 2,
      "should": [
        {
          "term": {
            "title": "java"
           }
        },
        {
          "term": {
            "title": "编程"
          }
        },
        {
          "term": {
            "title":  "思想"
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "title": {}
    }
  }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.