繁体   English   中英

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

[英]NEST Elastic search empty values in Documents result

弹性搜索菜鸟问题。

在阅读了一些关于 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();
}

调试器结果[![结果][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 ,因为第一个添加了带有帕斯卡大小写的索引和后一个骆驼大小写。 可能是配置/设置,但使用 ElasticClient 解决了我的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM