Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple wildcards in one query in elasticsearch

curl localhost:9200/tweet/posts/_search -d '{
  "query": {
    "and": [
      {
        "wildcard": {
          "_all": "*pet*"
        }
      },
      {
        "wildcard": {
          "_all": "*rom*"
        }
      }
    ]
  }
}'

This gives me a parse exception. I want to run a MySQL like(%test%) type query with an AND condition. Is there any other good way to do in elasticsearch.

like image 944
user2742004 Avatar asked May 15 '14 14:05

user2742004


People also ask

What is wildcard in Elastic search?

A wildcard operator is a placeholder that matches one or more characters. For example, the * wildcard operator matches zero or more characters. You can combine wildcard operators with other characters to create a wildcard pattern.

What is wildcard queries?

To locate a specific item when you can't remember exactly how it is spelled, try using a wildcard character in a query. Wildcards are special characters that can stand in for unknown characters in a text value and are handy for locating multiple items with similar, but not identical data.

How do you do a wildcard in Kibana?

There are two wildcard expressions you can use in Kibana – asterisk (*) and question mark (?). * matches any character sequence (including the empty one) and ? matches single characters. Since these queries are performed across a large number of terms, they can be extremely slow.


1 Answers

Maybe something like this?

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "_all": {
              "value": "*pet*"
            }
          }
        },
        {
          "wildcard": {
            "_all": {
              "value": "*rom*"
            }
          }
        }
      ]
    }
  }
}
like image 95
Alcanzar Avatar answered Sep 28 '22 06:09

Alcanzar