簡體   English   中英

如何通過使用日期作為彈性搜索的字符串比較來獲取文檔?

[英]How to get documents by using date as the string comparison from elastic search?

我正在調用ElasticSearch獲取文檔,然后將其加載到 memory 中。我有一個使用DateRange的以下代碼,它說給我的文檔大於currentDocumentTime

ISearchResponse<DataHolder> docManifests = await queryClient.SearchAsync<DataHolder>(search => search
    .Index("full_processVersion")
    .Type("ProcessVersion")
    .Query(query => query
        .DateRange(dateRangeQuery => dateRangeQuery
            .Field("DocumentCreatedDate")
            .GreaterThan(currentDocumentTime.Value))));

現在我在想是否有任何方法可以修改上述查詢,而不是在currentDocumentTime上使用GreaterThan查詢 - 我可以說給我所有GreaterThanLessThan currentDocumentTime的文檔。

基本上想法是進行字符串比較,這意味着給我任何與currentDocumentTime不匹配的日期文檔

例如,如果currentDocumentTime10 月 10 日,假設有一些文檔是 10 月 9 日的,所以我也應該能夠得到它。

這有可能做到嗎?

您也可以在日期類型字段上使用term 所以,你的 elasticsearch 查詢是這樣的:

{
 "query": {
   "bool": {
     "must_not": [
       {
         "term": {
               "DocumentCreatedDate": "Your Requested time"
             }
        }
     ]
   }
 }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM