微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NEST Elastic 搜索文档结果中的空值

如何解决NEST Elastic 搜索文档结果中的空值

弹性搜索菜鸟问题。

在阅读了一些关于 SO 的问题后,我想将一些数据发布到我的索引中,但我在获取结果时遇到了一些麻烦。

我收到一份文件(如预期),但所有属性都为空。字节数 740 与 Postman 中接收的字节数相匹配。我怀疑数据没有以某种方式正确映射..

代码

var client = CreateCloudClient();
var indexName = "index-b";
var mustClauses = new List<QueryContainer>();

mustClauses.Add(new WildcardQuery
{
    Field = new Field("FirstName"),Value = "*ralf*"
});

var searchRequest = new SearchRequest<ProfileEntity>(indexName)
{
    Query = new BoolQuery { Must = mustClauses }
};

var searchResponse = await client.SearchAsync<ProfileEntity>(searchRequest);
if (searchResponse.Hits.Any())
{
    var person = searchResponse.Hits.First();
}

调试结果

[![result][1]
[1]: https://i.stack.imgur.com/Ld5Wb.png

使用 Postman 时:

GET ../westeurope.azure.elastic-cloud.com:9243/index-b/_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "FirstName": "*ralf*"
                    }
                }
            ]
        }
    }
}

我得到:

{
    "took": 1,"timed_out": false,"_shards": {
        "total": 1,"successful": 1,"skipped": 0,"Failed": 0
    },"hits": {
        "total": {
            "value": 1,"relation": "eq"
        },"max_score": 1.0,"hits": [
            {
                "_index": "index-b","_type": "_doc","_id": "0ec623e7-3837-4e83-808d-fed01398d1ab","_score": 1.0,"_source": {
                    "Id": 0,"ProfileId": "0ec623e7-3837-4e83-808d-fed01398d1ab","FirstName": "Ralf","LastName": "de K","BirthDate": "1999-09-19T00:00:00Z","BirthPlace": "Zwolle","BirthPlaceLocation": {
                        "Longitude": 41.9074,"Latitude": -78.7911
                    },"City": "Zwolle","Email": "email@example.org","ObjectIdentifier": "0ec623e7-3837-4e83-808d-fed01398d1ab","MobileNumber": "06123123123","Height": 2,"BodyBuild": 0,"Ethnicity": 8,"Education": 3,"Gender": 2,"Created": "0001-01-01T00:00:00","Updated": "0001-01-01T00:00:00"
                }
            }
        ]
    }
}

解决方法

这是我自己的错误。我使用 ElasticLowLevelClient 添加了一个新索引,我(可能)应该使用 ElasticClient 因为第一个添加了带有 pascal 外壳和后一个驼峰外壳的索引。可能是一个配置/设置,但 usinf ElasticClient 解决了我的问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?