2014-09-02 173 views
0
我有一些問題的查詢

,我有一個嵌套的文件elasticsearch查詢在嵌套查詢用PHP

Array 
(
    [took] => 2 
    [timed_out] => 
    [_shards] => Array 
     (
      [total] => 5 
      [successful] => 5 
      [failed] => 0 
     ) 

    [hits] => Array 
     (
      [total] => 1 
      [max_score] => 1 
      [hits] => Array 
       (
        [0] => Array 
         (
          [_index] => holiday 
          [_type] => holiday 
          [_id] => 31245 
          [_score] => 1 
          [_source] => Array 
           (
            [username] => john thomas 
            [user] => 3 
            [info] => test 
            [phone] => 166872 
            [data] => Array 
             (
              [foo] => 28865 
              [bar] => new test 
             ) 

           ) 

         ) 

       ) 

     ) 

) 

當我運行與elasticsearch PHP庫

$client = new Elasticsearch\Client(); 

$params['index'] = 'holiday'; 
$params['type'] = 'holiday'; 
$params['body']['query']['match']['phone'] = '166872'; 

$results = $client->search($params); 

echo '<pre>' , print_r($results) , '</pre>'; 
的標準查詢

我得到一個結果。但是,當我更改查詢參數來搜索富

$params['body']['query']['match']['data']['foo'] = '28865'; 

我得到被拋出

{ 
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; 
      shardFailures {[9J2ZatYTTV2Sk8LQFKFeXg][holiday][2]: 
      SearchParseException[[holiday][2]: from[-1],size[-1]: 
       Parse Failure [Failed to parse source [ 
       { 
        "query": { 
        "match": { 
         "data": { 
         "foo": "28865" 
         } 
        } 
        } 
       } 
       ]]]; 
      nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][3]: 
      SearchParseException[[holiday][3]: from[-1],size[-1]: 
       Parse Failure [Failed to parse source [ 
       { 
        "query": { 
        "match": { 
         "data": { 
         "foo": "28865" 
         } 
        } 
        } 
       } 
       ]]]; 
      nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][0]: 
      SearchParseException[[holiday][0]: from[-1],size[-1]: 
       Parse Failure [Failed to parse source [ 
       { 
        "query": { 
        "match": { 
         "data": { 
         "foo": "28865" 
         } 
        } 
        } 
       } 
       ]]]; 
      nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][1]: 
      SearchParseException[[holiday][1]: from[-1],size[-1]: 
       Parse Failure [Failed to parse source [ 
       { 
        "query": { 
        "match": { 
         "data": { 
         "foo": "28865" 
         } 
        } 
        } 
       } 
       ]]]; 
      nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][4]: 
      SearchParseException[[holiday][4]: from[-1],size[-1]: 
       Parse Failure [Failed to parse source [ 
       { 
        "query": { 
        "match": { 
         "data": { 
         "foo": "28865" 
         } 
        } 
        } 
       } 
       ]]]; 
      nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }]", 
    "status": 400 
} 

任何想法,爲什麼嵌套查詢是打破一個例外?

回答

3

如果使用默認映射,data字段已動態映射到object(文檔here)類型。

因此,在您的object的子屬性查詢,你應該使用點符號這樣的:

{ 
    "query": { 
    "match": { 
     "data.foo": "28865" 
    } 
    } 
}