Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch the terms filter raise "filter does not support [mediatest]"

my query is like this:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "online": 1
              }
            },
            {
              "terms": {
                "mediaType": "flash"
              }
            }
          ]
        }
      }
    }
  }
}

it raise a QueryParsingException [[comos_v2] [terms] filter does not support [mediaType]],of which the field "mediaType" exactly does not exist in mapping. my question is why term filter does not raise the Exception?

like image 600
gwecho huang Avatar asked May 21 '15 02:05

gwecho huang


2 Answers

The above is not a valid Query DSL. In the above Terms filter the values to "mediaType" field should be an array

It should be the following :

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "online": 1
              }
            },
            {
              "terms": {
                "mediaType": ["flash"]
              }
            }
          ]
        }
      }
    }
  }
}
like image 58
keety Avatar answered Nov 20 '22 03:11

keety


Its 2021 I'm using .keyword for an exact text match but you can just as easily omit:

{"query":
  {"bool":
    {"must":
      [
        {"term":
          {"variable1.keyword":var1Here}
        },
        {"term":
          {"variable2.keyword":var2Here}
        }
      ]
    }
  }
}
like image 27
Chris Avatar answered Nov 20 '22 04:11

Chris