16

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?

gwecho huang
  • 579
  • 2
  • 6
  • 13

3 Answers3

34

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"]
              }
            }
          ]
        }
      }
    }
  }
}
keety
  • 17,231
  • 4
  • 51
  • 56
2

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}
        }
      ]
    }
  }
}
Chris
  • 18,075
  • 15
  • 59
  • 77
0

Its simply a matter of "term" vs "terms". Very easy to miss the plural / single aspect of it.

I had a very similar error with this query, in which I was trying to delete a specific zone:

'{"query":{"terms":{"zoneid":25070}}}'

I was getting an error when I ran the above query.

As soon as changed "terms" to "term" the query executed with no issues, like this:

'{"query":{"term":{"zoneid":25070}}}'
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29