2015-04-02 66 views
0

鑑於爲ElasticSearch不工作

string author = "John Smith"; 

下使用NEST拉姆達查詢NEST TermQuery工作:

string firstname = author.Split().First().ToLower(); 
var searchResults = client.Search<Magazine>(s => s.From(0).Size(5000).Query(q => q.Term(p => p.Author, author))); 

但是,使用OIS(對象初始化語法)相同的查詢不起作用:

author = author.Split().First().ToLower(); 

QueryContainer query = new TermQuery 
{ 
    Field = "Author", 
    Value = author 
}; 

var searchRequest = new SearchRequest 
{ 
    From = 0, 
    Size = 10, 
    Query = query 
}; 

var searchResults = client.Search<Magazine>(searchRequest); 

出了什麼問題?

+0

這應該會幫助你http://stackoverflow.com/questions/28312465/elasticsearch-nest-library-wired-behavior/28333375 – Rob 2015-04-02 18:21:07

回答

0

嘗試駱駝套的字段名稱: - 我認爲這是在使用OIS語法或原始查詢時需要的。

author = author.Split().First().ToLower(); 

QueryContainer query = new TermQuery 
{ 
    Field = "author", 
    Value = author 
}; 

var searchRequest = new SearchRequest 
{ 
    From = 0, 
    Size = 10, 
    Query = query 
}; 

var searchResults = client.Search<Magazine>(searchRequest);