NEST C#不返回任何结果,但查询DSL返回结果 [英] Return no result for NEST C# but Query DSL return result

查看:89
本文介绍了NEST C#不返回任何结果,但查询DSL返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询DSL,当我直接在ElasticSearch上查询时返回正确的结果

I have this Query DSL which return the correct result when I query directly at ElasticSearch

GET /person/_search
{
  "query": {
    "match": {
          "nameDetails.nameValue.firstName": {
            "query": "Fawsu"
          }
        }
    }
  }
}

但是在NEST C#中,它不返回任何结果.我可以知道我的语法有什么问题吗?

But in NEST C#, it doesn't return any result. May I know what's wrong with my syntax?

        var response = _elasticClient.Search<Person> (s => s
            .Index("person")
            .Query(q => q
                .Match(m => m
                    .Field(f => f.NameDetails.Name.First().NameValue.FirstName)
                    .Query("Fawsu")
                )
            )
        );

        var response = _elasticClient.Search<Person> (s => s
            .Index("person")
            .Query(q => q
                .Match(m => m
                    .Field(f => f.NameDetails.Name[0].NameValue.FirstName)
                    .Query("Fawsu")
                )
            )
        );

我如何查看NEST生成的查询来解决此问题?

How do I see the query generated by NEST to troubleshoot this?

推荐答案

.Field(f => f.NameDetails.Name [0] .NameValue.FirstName)中的表达式看起来像它与预期的字符串相比,对象图有一个额外的名称 Name .我希望表达式的输出是

The expression in .Field(f => f.NameDetails.Name[0].NameValue.FirstName) looks like it has an extra level, Name, to the object graph compared to the expected string. I would expect the output of the expression would be

nameDetails.name.nameValue.firstName

与查询中的字段" nameDetails.nameValue.firstName" 不匹配.

which will not match the field "nameDetails.nameValue.firstName" in the query.

您可以看到NEST发送到的内容Elasticsearch有多种方式

这篇关于NEST C#不返回任何结果,但查询DSL返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆