2016-06-10 76 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 
     } 
    } 
} 
相關問題