E. Smailov
E. Smailov

Reputation: 3

Query "like" and "or" in Elasticsearch

I am using elasticsearch for filtering and searching from json file and I am newbie in this technology. So I am little bit confused how to write like query in elasticsearch.

select * from table_name where 'field_name1' like 'a%' or 'field_name2' like 'a%'

This is oracle query. How do I write this query in Elasticsearch? I am using elasticsearch version 6.8.13

Upvotes: 0

Views: 1342

Answers (1)

ThangLeQuoc
ThangLeQuoc

Reputation: 3073

You will need to use the Elasticsearch Wildcard query, combined inside a Bool query.
In case you're new, should in Elasticsearch bool query context is pretty much equals to OR in SQL language.

{
    "query": {
        "bool": {
            "should": [
                {
                    "wildcard": {
                        "field_name1": {
                            "value": "a*"
                        }
                    }
                },
                {
                    "wildcard": {
                        "field_name2": {
                            "value": "a*"
                        }
                    }
                }
            ]
        }
    }
}

Upvotes: 4

Related Questions