[英]IBM Bluemix Discovery - query parameter
我已經在我的bluemix帳戶上創建了Discovery服務。 我想從nodejs應用程序查詢我的文檔。
我已經建立了帶有某種聚合的查詢,並使用了bluemix在線工具對其進行了測試,並且它運行良好。
現在,當我從代碼中查詢集合時,無論我的參數是什么,我總是會收到所有帶有豐富文本的文檔,依此類推。 我想我不知道如何將查詢屬性發送到服務(如過濾器和聚合)。
這是我的代碼:
var queryParams = {
query:'CHLOE RICHARDS',
return:'title',
count:1,
aggregations:'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)'
};
discovery.query({environment_id:that.environment_id, collection_id:that.collection_id, query_options:queryParams }, function(error, data) {
if(error){
console.error(error);
reject(error);
}
else{
console.log(JSON.stringify(data, null, 2));
resolve(data.matching_results);
}
});
結果始終是:
{
"matching_results": 28,
"results": [
{
"id": "fe5e2a38e6cccfbd97dbdd0c33c9c8fd",
"score": 1,
"extracted_metadata": {
"publicationdate": "2016-01-05",
"sha1": "28434b0a7e2a94dd62cabe9b5a82e98766584dd412",
"author": "Richardson, Heather S",
"filename": "whatever.docx",
"file_type": "word",
"title": "no title"
},
"text": "......
與query_option
參數的值query_option
。 你能幫助我嗎?
編輯
我使用了query:"text:CHLOE RICHARDS"
而不是query_options:queryParams
,並且運行良好。 現在我的問題仍然是找到正確的參數格式來添加我想要的聚合
編輯2
因此,我在Github上更仔細地查看了IBM的示例 ,現在參數的格式如下:
const queryParams = {
count: 5,
return: 'title,enrichedTitle.text',
query: '"CHLOE RICHARDS"',
aggregations: [ 'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)' ],
environment_id: '1111111111',
collection_id: '11111111111'
};
如果我僅使用查詢屬性,則效果很好。 現在,如果我只使用一個aggregations
,那么所有文檔都會作為結果發送回去(這是可以理解的),但是我沒有匯總部分,因此無法訪問文檔中的專有名稱列表。
您的查詢看起來不正確。 我要使用query
那么您將需要構建一個查詢搜索,例如text:"CHLOE RICHARDS"
如果要執行自然語言查詢,則應設置參數natural_language_query
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.