简体   繁体   中英

ElasticSearch and NEST Query Issue

SOLVED : The URI was incorrect. Was "h||p://#.#.#.#/:9200" and should have been "h||p://#.#.#.#:9200". This was causing the API to change the port number to 80. Surprised the API actually was able to connect to ElasticSearch instance with the incorrect port number.

I'm new to NEST and ElasticSearch and trying to put together aa simple MatchAll query in NEST.

When I perform a MatchAll from Sense

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

I get all the movie objects in the movies index.

But when I try the NEST query

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

I get nothing back. Tried setting the return type to a movie class, and still no results.

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

Also tried .AllIndices() and/or .AllTypes() per this reply Searching an elasticsearch index with NEST yields no results

Any ideas?

EDIT: Heres the connection string setting the default index.

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

You have to check for IsValid on result to see if the call succeeded or not.

result.ConnectionStatus will hold all the information you need to determine what went wrong.

If you'd like to throw exceptions instead you can enable that by calling:

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

on your ConnectionSettings

Calling ToString on an ConnectionStatus object prints all the request and response details in human readable form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM