2016-06-10 60 views
2

我一直在搜索弹性搜索文档进行搜索,但不幸的是我无法理解我应该如何通过主题学习弹性搜索主题。如何在弹性搜索中进行多场匹配

在这里,我要搜索my_deezer指数中的所有歌曲有艺术家=“嗒嗒”和年份= 2004

我使用PHP客户端和它的返回错误,当我提供多个字段相匹配。

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(); 
} 

另外,我要寻找一些链接,我怎么能执行不同的查询操作,如搜索,其中场x大于/小于/等于没有一定的价值。

感谢

//错误

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?]; }] 
+0

返回什么错误? – Marcus

+0

已更新问题 –

+1

尝试添加''query'=> ['must'=> ['match => [...'注意''must'=> [' – Marcus

回答

2

你有两个条件,就可以使用布尔必须查询,查询将

{ 

    "query": { 
    "bool" : { 
    "should" : [ 
      { 
       "term" : { "artist" : "blah" } 
      }, 
      { 
       "term" : { "year" : "2004" } 
      } 
     ] 
    } 
} 

用于获取结果大于第二部分小于,有范围查询

{ 
    "range" : { 
      "age" : { "from" : 10, "to" : 20 } 
     } 
} 

{ 
    "range" : { 
     "age" : { 
      "gte" : 10, 
      "lte" : 20 
     } 
    } 
} 
相关问题