[英]elasticsearch how do i query (search) in single document?
假設索引的名稱是 index & 文檔 1 的 id 是“1”
如何在單個文檔中查詢?
像這樣的東西..
GET index/_search
{
"query": {
"id": "1",
"terms": ["is this text in document 1?"]
}
}
或者
GET index/_doc/1/_search
{
...
}
據我發現,
GET test/_doc/_search
{
"query": {
"terms" : {
"_id" : ["1"]
}
}
}
這將獲得“1”的文檔 ID,但不能執行任何進一步的查詢。
我想在單個文檔中查詢的原因是因為我的應用程序正在使用實時新聞視圖,一旦從服務器檢索到新聞,我想在 elasticsearch 中搜索它以進行關鍵工作突出顯示和垃圾郵件過濾。
您必須使用Boolean Query 編寫查詢
最好的方法是在過濾器下指定 id 查詢,因為它不會影響評分。 接下來,您可以根據需要在 must、must_not 和 should 下指定查詢:
GET index/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"field": "value"
}
}
],
"must_not": [],
"should": [],
"filter": [
{
"terms": {"_id": ["1"]}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.