Search code examples
c#elasticsearchnest

Nest aggregation returns error {Invalid NEST response built from a unsuccessful low level call on POST: /people/_search?typed_keys=true}


I'm performing a simple aggregation query on elastic search using nest asp per the documentation on getting started. However i get the error {Invalid NEST response built from a unsuccessful low level call on POST: /people/_search?typed_keys=true}. I am using nest 7.0.0. with an elasticsearch cloud service with is elasticsearch 7.0.0. The code below illustrates how i have setup the elasticclient, and how i am performing the query.

I have used the same connection to perform a successfull query operation, hence i think my connection is okay, and the index setup is also okay.

var settings = new ConnectionSettings("my_elasticsearch_url").DefaultIndex("people");

ElasticClient elasticClient = new ElasticClient(settings);

Person person = new Person()
            {
                FirstName = "George",
                LastName = "Ouma"
            };

            var indexResponse = elasticClient.IndexDocument(person);

            var searchResponse = elasticClient.SearchAsync<Person>(s =>
                s.Size(0)

                .Query(q => q
                    .Match(m=>m
                        .Field(f=>f.FirstName)
                        .Query("George")
                    )
                )
                .Aggregations(a => a
                    .Terms("first_names", ta => ta
                        .Field(f => f.FirstName)
                    )
                )
            ).GetAwaiter().GetResult();            

var aggregations = searchResponse.Aggregations.Terms("first_names");

I expect the aggregate results, but i get null and on inspection the searchResponse object, i get the error message {Invalid NEST response built from a unsuccessful low level call on POST: /people/_search?typed_keys=true}


Solution

  • All credits to @Rob, the solution to this problem is to add the suffix keyword to the field as follows: .Field(f => f.FirstName.Suffix("keyword"))