2017-10-11 30 views
0

一直試圖找到一種方法來做到這一點現在幾天。我查看了'bool','constant_score','filtered'查詢,其中沒有一個似乎能夠想出我想要的結果。有沒有一種方法可以通過彈性搜索進行搜索以獲取ID中包含ID的所有結果?

一個有接近是「ids」查詢(不正是我在這個問題標題所描述)的一個問題是,我想搜索的關鍵是沒有的「_id的價值彈性搜索索引。相反,它是 'posterId' 在index如下:

"_index": "activity", 
"_type": "activity", 
"_id": "<unique string id>", 
"_score": null, 
    "_source": { 
    ... 
    misc keys 
    ... 
    "posterId": "<QUERY BASED ON THIS VALUE>", 
    "time": 20171007173623 
} 

查詢返回基於_id值:

ids : { 
    type : "activity", 
    values : ["<unique string id>", ...] 
} 

如下所示:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html

如何我想我的查詢工作:

posterId : { 
    type : "activity", 
    values : [<list of posterIds>] 
} 

返回所有索引已包含在"<list of posterIds>"

<編輯posterIds>我想作爲並列通過我posterIds的列表中的每個成員循環爲此在一個查詢,因爲我還需要基於時間鍵進行排序,並能查詢頁面。

那麼,有沒有人知道一個內置的查詢,這樣做或工作?


附註:如果你覺得你要downvote這個請你只發表評論爲什麼,我快要被禁止,我已經通過所有的準則閱讀,我覺得我以下他們但我的問題很少表現良好。 :(這將是非常讚賞

編輯:

{ 
    "activity" : { 
    "aliases" : { }, 
    "mappings" : { 
     "activity" : { 
     "properties" : { 
      "-Kvp7f3epvW_dXSONzKj" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "actionId" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "actionType" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "activityType" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "attachedId" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "attachedType" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "cardType" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "noteTitleDict" : { 
      "properties" : { 
       "noun" : { 
       "type" : "text", 
       "fields" : { 
        "keyword" : { 
        "type" : "keyword", 
        "ignore_above" : 256 
        } 
       } 
       }, 
       "subject" : { 
       "type" : "text", 
       "fields" : { 
        "keyword" : { 
        "type" : "keyword", 
        "ignore_above" : 256 
        } 
       } 
       }, 
       "verb" : { 
       "type" : "text", 
       "fields" : { 
        "keyword" : { 
        "type" : "keyword", 
        "ignore_above" : 256 
        } 
       } 
       } 
      } 
      }, 
      "posterId" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "segueType" : { 
      "type" : "text", 
      "fields" : { 
       "keyword" : { 
       "type" : "keyword", 
       "ignore_above" : 256 
       } 
      } 
      }, 
      "time" : { 
      "type" : "long" 
      } 
     } 
     } 
    }, 
    "settings" : { 
     "index" : { 
     "creation_date" : "1507678305995", 
     "number_of_shards" : "5", 
     "number_of_replicas" : "1", 
     "uuid" : "<id>", 
     "version" : { 
      "created" : "5010199" 
     }, 
     "provided_name" : "activity" 
     } 
    } 
    } 
} 
+0

發佈您的索引映射和您嘗試的查詢。此外,一些示例文檔將有所幫助。 –

+0

是不是我映射的第一個代碼塊的索引?還有與我用過的其他查詢或索引相關的文檔?我加了一個查詢我知道的工作方式類似於我想要實現的鏈接。 - 感謝您的評論 – thoseguysintown

+0

沒有,粘貼從該得到什麼:'GET活動/' 沒有文件,我說:「文件」。您存儲在索引中的文檔。 –

回答

0

我知道你在尋找的是一個術語查詢

{ 
    "query": { 
     "constant_score" : { 
      "filter" : { 
       "terms" : { "user" : ["kimchy", "elasticsearch"]} 
      } 
     } 
    } 
} 

此發現含有的確切期限Kimchy或elasticsearch文件用戶字段的索引您可以在這裏閱讀更多關於https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html

在您的情況下,您需要更換

  1. 用戶posterId.keyword
  2. Kimchy,並與所有的posterIds

記住elasticsearch一個方面的查詢是大小寫敏感的關鍵字字段不使用小寫分析器(這意味着它會在收到相同的情況下保存/索引值)

+0

咦,當我嘗試這樣做它永遠不會返回任何結果。我認爲我已經找到了解決方案。一旦我推出這個更新並清理一下,我就會發布它。 – thoseguysintown

+0

@thoseguysintown檢查下列事項:您使用的是正確的情況下,您在搜索上。關鍵詞內部的場,你在使用方面的查詢,而不是詞語查詢? –

相關問題