巢式汇总返回错误{无效的NEST响应是由于POST上的低级调用失败而生成的:/ people / _search?typed_keys = true}

时间:2019-05-10 11:26:13

标签: c# elasticsearch nest

根据入门文档,我正在使用nest asp对弹性搜索执行简单的聚合查询。但是我收到错误{Invalid NEST response built from a unsuccessful low level call on POST: /people/_search?typed_keys=true}。我正在使用Nest 7.0.0。与Elasticsearch Cloud Service一起使用的是Elasticsearch 7.0.0。下面的代码说明了我如何设置elasticclient以及如何执行查询。

我使用相同的连接来执行成功的查询操作,因此我认为我的连接没问题,索引设置也没问题。

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

我希望获得合计结果,但是得到null并检查searchResponse对象时,我得到了错误消息{Invalid NEST response built from a unsuccessful low level call on POST: /people/_search?typed_keys=true}

1 个答案:

答案 0 :(得分:0)

所有积分都归@Rob所有,解决此问题的方法是将后缀keyword添加到字段中,如下所示:.Field(f => f.FirstName.Suffix("keyword"))