2017-02-14 97 views
1

我在彈性搜索中遇到了問題。在控制檯Kibana,我正在執行此代碼,在ElasticSearch中搜索

GET bounce_gmd/_search 
{ 
"query": { "match_phrase": { "date_added": "2017-02-08" } }, 
    "size": 0, 
    "aggs": { 
    "date_added": { 
    "terms": { 
     "field": "bounce_type.keyword" 
     } 
    } 
    } 
} 

而且我有這個結果。

{ 
"took": 1, 
"timed_out": false, 
"_shards": { 
"total": 5, 
"successful": 5, 
"failed": 0 
}, 
"hits": { 
"total": 129812, 
"max_score": 0, 
"hits": [] 
}, 
........................... and many more lines. 

但是,當我從我的laravel項目運行我沒有這個結果。 我的PHP代碼看起來像這樣,

$params['index'] = $index_name; 
$params['type'] = $index_name; 
$params['body'] = $json; 
$params['body']['query']['match_phrase']['date_added'] = $now_time; 
$params['body']['size']=0; 
$params['body']['aggs']['bounce_type']['terms']['field']='bounce_type.keyword'; 
$response = $client->search($params); 

這裏$ INDEX_NAME = 'bounce_gmd' 和$ now_time = 「2017年2月8日」。

但是我的回答是,

Answer

我改變了代碼,

$json='{ 
"query": { "match_phrase": { "date_added": "2017-02-08" } }, 
    "size": 0, 
    "aggs": { 
    "date_added": { 
     "terms": { 
     "field": "bounce_type.keyword" 
     } 
     } 
    } 
    } 
    '; 
$params = [ 
     'index' => $index_name, 
     'type' => $index_name, 
     'body' => $json 
    ]; 

但得到的答案仍然是相同的。我不明白是什麼問題。請幫幫我。

+0

你能打印你的php代碼所做的查詢嗎? –

+0

你想如何查詢SQL表單?我試着從這個頁面查詢。 https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_search_operations.html – Avishake

回答

0

爲什麼你指定0的大小?它應該有一定的價值。你的聚合也可以包含可能的大小(它應該爲每個aggs採用最大可能的選項)。一些工作查詢的例子:

{ 
    "from" : 0, 
    "size" : 10, 
    "query" : { 
    "match" : { 
     "body": 
     { 
     "query":"press key handler ", 
     "operator":"or", 
     "analyzer":"english" 
     } 
     } 
    }, 
    "aggs" : { 
    "category_aggs" : { "terms" : { "field": "category", "size":25}}, 
    "year_aggs" : { "terms" : { "field": "year", "size":30}}, 
    "post_type_aggs" : { "terms" : { "field": "post_type", "size":2}} 
    } 
} 
+0

我將代碼更改爲「{ 」query「:{」match「:{」body「 :{ 「DATE_ADDED」: 「2017年2月8日」}}}, 「從」:0, 「大小」:10, 「AGGS」:{ 「DATE_ADDED」:{ 「術語」:{ 「場」: 「bounce_type.keyword」, \t \t 「大小」:25 } } } }'。但有另一個錯誤。 'parsing_exception:[match] query does not support [date_added]' – Avishake

+0

@Avishake「body」是我的示例字段名稱,在您的情況下,而不是「body」使用「date_added」 – jgr