user19055
user19055

Reputation: 73

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 a a 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");

Upvotes: 1

Views: 1778

Answers (1)

Martijn Laarman
Martijn Laarman

Reputation: 13536

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.

Upvotes: 1

Related Questions