2016-09-07 59 views
0

得到了一些與NEST相關的問題。以下是ES中的一些文檔。NEST Fluent DSL查詢一些URL字段

enter image description here

正如你可以看到我已經插入我的ES一些條目。我試着做一些這樣的查詢:

 var response = elastic.Search<ESIntegrationLog>(s => s 
          .Index("20160806") 
          .Type("esintegrationlog") 
          .Query(q => 
           q.Term(p => p.CalledBy, "lazada") 
          ) 
          .Sort(ss => ss.Descending(p => p.CalledOn)) 
          .Take(300) 
         ); 

結果如我所料,我找到了入口。但是當我試圖用'callPoint'查詢時,我無法找到任何結果。下面是代碼:

 var response = elastic.Search<ESIntegrationLog>(s => s 
          .Index("20160806") 
          .Type("esintegrationlog") 
          .Query(q => 
           q.Term(p => p.CallPoint, "/cloudconnect/api/xxxxxxx/v1") 
          ) 
          .Sort(ss => ss.Descending(p => p.CalledOn)) 
          .Take(300) 
         ); 

我已經嘗試編碼URL,但仍然沒有發現任何東西。有任何想法嗎?

更新:我使用「匹配」解決案例。

.Query(q => 
    //q.Term(p => p.CallPoint, "abcdefg") 
    q.MatchPhrasePrefix(c=> c.Field(d=> d.CallPoint).Query("/cloudconnect/api/xxxxxxx/v1")) 
) 

回答

2

我懷疑callPoint是分析string字段,它已經由標準分析儀分析。通過查看20160806索引中的映射,您將能夠看到callPoint的映射方式。使用Sense

GET 20160806 

如果callPoint映射是{ "type" : "string" }則輸入將在索引時間進行分析。你可以看到標準分析器將如何使用_analyze API

POST _analyze 
{ 
    "text" : "/cloudconnect/api/xxxxxxx/v1", 
    "analyzer": "standard" 
} 

產生以下令牌

{ 
    "tokens": [ 
     { 
     "token": "cloudconnect", 
     "start_offset": 1, 
     "end_offset": 13, 
     "type": "<ALPHANUM>", 
     "position": 0 
     }, 
     { 
     "token": "api", 
     "start_offset": 14, 
     "end_offset": 17, 
     "type": "<ALPHANUM>", 
     "position": 1 
     }, 
     { 
     "token": "xxxxxxx", 
     "start_offset": 18, 
     "end_offset": 25, 
     "type": "<ALPHANUM>", 
     "position": 2 
     }, 
     { 
     "token": "v1", 
     "start_offset": 26, 
     "end_offset": 28, 
     "type": "<ALPHANUM>", 
     "position": 3 
     } 
    ] 
} 

A term query不分析查詢輸入,所以會試圖匹配查詢輸入作爲分析輸入在索引時已經對在callPoint字段中的倒排索引進行了分析。 A match query確實分析了查詢輸入,因此您可以按預期得到文檔匹配。或者,您可以將callPoint映射爲not_analyzed字符串字段,以便在索引時不對輸入進行分析並逐字索引。

+0

謝謝。幫助我很多。 – dausdashsan

+0

不用擔心,很高興幫助:) –