I have been searching elastic search documentation for searching but unfortunately I am unable to understand how should i learn elastic search topics by topics.
Here i want to search my_deezer index for all the songs that has artist = "blah" and year = 2004.
I am using PHP client and its returning errors when i am supplying multiple fields to match.
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_deezer',
'type' => 'song',
'body' => [
'query' => [
'match' => [
'artist' => 'blah',
'year' => 2004
]
]
]
];
try {
$response = $client->search($params);
print_r($response);
} catch (Exception $e) {
echo $e->getMessage();
}
Also, I am looking for some links as how can i perform different query actions such as search where field x is greater than / less than / not equals to some value.
Thanks
// Error
SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[hIY53G4ySJm0xQz0Lpqjxg][my_deezer][0]: SearchParseException[[my_deezer][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"match":{"artist":"jal","year":2001}}}]]]; nested: QueryParsingException[[my_deezer] [match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]; }{[hIY53G4ySJm0xQz0Lpqjxg][my_deezer][1]: SearchParseException[[my_deezer][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"match":{"artist":"jal","year":2001}}}]]]; nested: QueryParsingException[[my_deezer] [match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]; }{[hIY53G4ySJm0xQz0Lpqjxg][my_deezer][2]: SearchParseException[[my_deezer][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"match":{"artist":"jal","year":2001}}}]]]; nested: QueryParsingException[[my_deezer] [match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]; }{[hIY53G4ySJm0xQz0Lpqjxg][my_deezer][3]: SearchParseException[[my_deezer][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"match":{"artist":"jal","year":2001}}}]]]; nested: QueryParsingException[[my_deezer] [match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]; }{[hIY53G4ySJm0xQz0Lpqjxg][my_deezer][4]: SearchParseException[[my_deezer][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"match":{"artist":"jal","year":2001}}}]]]; nested: QueryParsingException[[my_deezer] [match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]; }]
'query' => [ 'must' => [ 'match => [...
note the'must' => [
– mferly'query' => [ 'must' => [ [ 'range' => [ 'year' => [ 'gte' => 2001 ] ] ] ] ]
wheregte
means greater than/equal to and replace withlte
for less than/equal to – mferly