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?
The multi_match query provides a convenient shorthand way of running the same query against multiple fields.
Boolean, or a bool query in Elasticsearch, is a type of search that allows you to combine conditions using Boolean conditions. Elasticsearch will search the document in the specified index and return all the records matching the combination of Boolean clauses.
Minimum Should Match is another search technique that allows you to conduct a more controlled search on related or co-occurring topics by specifying the number of search terms or phrases in the query that should occur within the records returned.
Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries. Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of clauses: Leaf query clauses.
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}}
]
}
}
}
}
}
You can approach this with the and
filter. For your example, something like:
{
"size": 100,
"query" : {"filtered" : {
"query" : {"match_all" : {}},
"filter" : {"and" : [
"term" : {"a": -23.4807339},
"term" : {"b": -46.60068}
]}
}}
}
Be sure to direct the query against the correct index and type. Note that I specified the size of the return set as 100 arbitrarily - you'd have to specify a value that fits your use case.
There's more on filtered queries here, and more on the and
filter here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With