Search code examples
sqlelasticsearchgeolocationmatch

elasticsearch match two fields


How can I get this simple SQL query running on elasticsearch ?

SELECT * FROM [mytype] WHERE a = -23.4807339 AND b = -46.60068

I'm really having troubles with it's syntax, multi-match queries doesn't work in my case, which query type should I use?


Solution

  • For queries like yours bool filter is preferred over and filter. See here the whole story about this suggestion and why is considered to be more efficient.

    These being said, I would choose to do it like this:

    {
      "query": {
        "filtered": {
          "filter": {
            "bool": {
              "must": [
                {"term": {"a": -23.4807339}},
                {"term": {"b": -46.60068}}
              ]
            }
          }
        }
      }
    }