Search query in Elastic Search Search query in Elastic Search elasticsearch elasticsearch

Search query in Elastic Search


Try this query using the Query String Query. There are quite a few other options from the documentation. The ability to search on some keywords will depend on the field mapping you have setup as well.

{    "query": {        "query_string" : {            "query" : "name:is AND (state:Y OR number:N6)"        }    }}

You need to treat the whole query_string query as a string. So the query would look something like this:

my $e = Search::Elasticsearch->new();my $results = $e->search(    index => 'mysite',    type => 'products',    size => 3,    body  => {        query => "(name:$word OR number:$word) AND status:Y"    });


filters are what you want:

PUT myindex/_search{  "query": {     "bool": {       "filter": [{         "should": [{           "match": {"name": "is" },          "term": {"number": "N6"}        }],        "must": {          "term": {"status": "Y"}        }              ]}    }  }}

This assumes you've made number and status as unanalyzed string or keyword types (depends on version) - which you should if there are a discrete number of values within those fields. Otherwise, swap term for match.