Search code examples
elasticsearchnest

ElasticSearch 6.x and NEST simple query


Actually I'm a newcomer to ElasticSearch and got stuck with just a simple NEST query. Here is my class to store data in ElasticSearch:

public class MyClass
{
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Language { get; set; }
}

I need to get documents by the Language (e.g. Language == "eng") I use the NEST 6.x

Here is the SerchDescriptor

searchDescriptor = new SearchDescriptor<MyClass>()
                .Index(indexName)
                .Query(q => q.Term("Language", "eng"));

it produces the request:

{
  "query": {
    "term": {
      "Language": {
        "value": "eng"
      }
    }
  }
}

but the right request is

{
  "query": {
    "term": {
      "Language": "eng"
    }
  }
}

How can I get the right request via NEST?


Solution

  • Both forms are valid; the former is the long form of term query that accepts other properties such as boost and _name.

    NEST typically serializes request types to the long form, and deserializes from the long form.