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 解决了我的问题。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...