IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
A more complicated example
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
A more complicated example
editLet’s construct a slightly more complicated example: a boolean query that contains both a filter and a query. This is a very common activity in elasticsearch queries, so it will be a good demonstration.
The curl version of the query:
curl -XGET 'localhost:9200/my_index/my_type/_search' -d '{
"query" : {
"bool" : {
"filter" : {
"term" : { "my_field" : "abc" }
},
"should" : {
"match" : { "my_other_field" : "xyz" }
}
}
}
}'
And in PHP:
$params = [
'index' => 'my_index',
'type' => 'my_type',
'body' => [
'query' => [
'bool' => [
'filter' => [
'term' => [ 'my_field' => 'abc' ]
],
'should' => [
'match' => [ 'my_other_field' => 'xyz' ]
]
]
]
]
];
$results = $client->search($params);