2014-02-13 124 views
1

已解决: URI不正确。是“h || p://#.#.#.#/:9200”,应该是“h || p://#.#.#.#:9200”。这导致API将端口号更改为80.令人惊讶的是,API实际上能够使用不正确的端口号连接到ElasticSearch实例。ElasticSearch和NEST查询问题

我是NEST和ElasticSearch的新手,尝试在NEST中放置一个简单的MatchAll查询。

当我从感

POST /movies/movie/_search 
{ 
    "query": { 
    "match_all": {} 
    } 
} 

我得到了电影指数中的所有影片对象进行MatchAll。

但是当我尝试了NEST查询

var result = client.Search(s => s.Type("movie").MatchAll()); 

我得不到任何回报。尝试将返回类型设置为电影类,但仍然没有结果。

public class Movie 
    { 
     public string title { get; set; } 
     public string director { get; set; } 
     public int year { get; set; } 
     public List<string> genres { get; set; } 
    } 

也试过.AllIndices()和/或每此回复 Searching an elasticsearch index with NEST yields no results

任何想法.AllTypes()?

编辑: 继承人连接字符串设置默认索引。

ConnectionSettings connection = new ConnectionSettings(uri).UsePrettyResponses().SetDefaultIndex("movies"); 

回答

1

你必须检查IsValidresult,看是否调用成功与否。

result.ConnectionStatus将包含您需要的所有信息以确定出错的地方。上ConnectionStatus对象打印

.SetConnectionStatusHandler(c=> { 
    if (!c.Success) 
     throw new Exception(c.ToString()); 
}) 

ConnectionSettings

调用toString人类可读的所有请求和响应的细节:

如果你想抛出异常,而不是您可以启用通过调用形成。

+0

感谢您的回复Martijn。 Intersting IsValid()方法实际上是在IQueryResponse对象中,而不是像文档状态那样的ElasticClient。 http://nest.azurewebsites.net/concepts/connecting.html – user19055