0

Hello I have the following query that I am running:

{
  "_source": [
    "source1",
    "source2",
    "source3",
    "source4",
  ],
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "must": {
        "filter": [
            {
            "term": {
              "_type": {
                "value": "someval1"
              }
            }
          },
          {
            "term": {
              "_type": {
                "value": "someval2"
              }
            }
          }
        ],
        "query_string": {
          "analyze_wildcard": "true",
          "query": "tesla*",
          "rewrite": "scoring_boolean"
        }
      }
    }
  },
  "size": 50,
  "sort": [
    "_score"
  ]
}

That is currently returning:

'"reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":343},"status":400}'

Any idea how to use multiple filters on a query? I was able to do it just fine on elastic 2.4 but since OR is now deprecated as well as filtered, I am a bit lost.

Thanks!

1 Answer 1

1

The syntax of the query is wrong. filter should not be wrapped into the must statement. It should be in the same level with must. Also bool queries must statement should be an array, not an object. So your query should look like this

{
    "_source":[
       "source1",
       "source2",
       "source3",
       "source4"
    ],
    "query":{
       "bool":{
          "minimum_should_match":1,
          "must":[
             {
                "query_string":{
                   "analyze_wildcard":"true",
                   "query":"tesla*",
                   "rewrite":"scoring_boolean"
                }
             }
          ],
          "filter":{
             "bool":{
                "should":[
                   {
                      "term":{
                         "_type":{
                            "value":"someval1"
                         }
                      }
                   },
                   {
                      "term":{
                         "_type":{
                            "value":"someval2"
                         }
                      }
                   }
                ]
             }
          }
       }
    },
    "size":50,
    "sort":[
       "_score"
    ]
 }

I think your filter is OR, that's why I wrap it inside should

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.