2016-09-07 42 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

不用担心,很高兴帮助:) –