【问题标题】:NEST Elastic search empty values in Documents resultNEST Elastic 在文档结果中搜索空值
【发布时间】:2021-04-15 20:06:32
【问题描述】:

弹性搜索菜鸟问题。

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

调试器结果

使用 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"
                }
            }
        ]
    }
}

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    这是我自己的错误。我使用ElasticLowLevelClient 添加了一个新索引,而我(可能)应该使用ElasticClient,因为第一个使用pascal 大小写添加索引,而后者添加了骆驼大小写。可能是配置/设置,但使用 ElasticClient 解决了我的问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多