2017-10-11 45 views
0

我在我的項目中使用彈性搜索。出於很多原因,我必須通過URI調用Elastic。像: 「http://localhost:9200//demo/localetranslatemodel/_search?default_operator=AND&q=localeId%3Adaefa52a-cada-4370-9ae5-6bcfb50a9cf8+name%3AlblCommon_PartCost彈性搜索uri調用返回一個字段

,這回:

{ 

    "took": 3, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
}, 
"hits": { 
    "total": 1, 
    "max_score": 8.272978, 
    "hits": [ 
     { 
      "_index": "demo", 
      "_type": "localetranslatemodel", 
      "_id": "31bb0b3f-ace5-4007-b619-009f3e76bafc", 
      "_score": 8.272978, 
      "_source": { 
       "translate": "Part cost", 
       "localeId": "daefa52a-cada-4370-9ae5-6bcfb50a9cf8", 
       "name": "lblCommon_PartCost", 
       "id": "31bb0b3f-ace5-4007-b619-009f3e76bafc" 
      } 
     } 
    ] 
} 
} 

所以我的問題是:我只能返回「翻譯:‘部分成本部分成本‘’或者說,對我來說非常好,唯一的?’ ? 我使用的HttpClient用於調用API,在ASP .NET項目。 非常感謝你的有用的答案,我想了一個星期做

所有的解決方案是爲我好如果我問一些不可能的事情(像只返回_source)

回答

0

是的。響應過濾可以做到這一點。

閱讀:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#common-options-response-filtering

您也可以要求具體領域而不是得到充分_source領域。取決於你真正需要的東西。見https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html

+0

哦,謝謝的,現在你我回: { 「命中」:{ 「點擊」:[ { 「_source」:{ 「翻譯」: 「部分費用」 } } ] } } 但我顯然不能只返回「零件成本」權利?我的意思是隻有價值 – blackstar012

+0

我不這麼認爲。 – dadoonet