0

I need to query 3000 data from ElasticSearch, and currently I am using multi_match for querying. Is there a way to match using an array of strings? Term is not usable as it only queries the exact value of the string.

Below is an example of an ideal request:

{

    "size": 1,
    "_source": ["_id"],
    "query": {
        "multi_match": {
            "query": ["val1", "val2"],
            "fields": [
                "name",
                "url"
            ]
        }
    }
}

EDIT:

Another use case would be like searching schools:

{

    "size": 1,
    "_source": ["_id"],
    "query": {
        "multi_match": {
            "query": ["school name 1", "school name 2"],
            "fields": [
                "name"
            ]
        }
    }
}

Consider the spaces of each values to be the whole school name.

1 Answer 1

1

multi_match doesn't accept and array of values but nothing prevents you from sending a string containing the values. The query string will be analyzed into two tokens val1 and val2 and each will be matched separately on each field.

{

    "size": 1,
    "_source": ["_id"],
    "query": {
        "multi_match": {
            "query": "val1 val2",
            "fields": [
                "name",
                "url"
            ]
        }
    }
}
Sign up to request clarification or add additional context in comments.

13 Comments

Thanks for the response. Is there any way that ElasticSearch has similar query like SQL that can compare the column's value from a list? eg: SQL's =ANY() or IN operator?
That's what the above query does under the hood, you just need to concatenate the array into a space separated string
What if the values have spaces in them? Are there any way to have separators in each values considering most values have two or more words? I'm still new to ElasticSearch
It would help to know your use case, because there are different ways of achieving what you want, but it depends on what you actually need. Feel free to expand on your use case
Just edited my question. My problem is that I need to query school names from ElasticSearch and I think that querying those schools as a form of list of values would be faster and more efficient.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.