elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

C# ElasticSearch嵌套-所有字段均为空

C# ElasticSearch嵌套-所有字段均为空,c#,elasticsearch,nest,C#,elasticsearch,Nest,我正在尝试使用NEST从弹性搜索中检索数据。一切都很好,但嵌套所有字段都返回null。但是,在调试模式下,我看到它正确地计算了文档的数量,但没有显示字段的值 我已经做了: 检查了地图,我觉得还不错 尝试字符串查询 试图获取源,然后读取数据 尝试 这些解决方案也无济于事 将Product.cs字段名称重命名为camelCase也没有帮助 这是我的密码 public class ElasticSearch { private ElasticClient _client; p

我正在尝试使用NEST从弹性搜索中检索数据。一切都很好,但嵌套所有字段都返回null。但是,在调试模式下,我看到它正确地计算了文档的数量,但没有显示字段的值

我已经做了:

  • 检查了地图,我觉得还不错
  • 尝试字符串查询
  • 试图获取源,然后读取数据
  • 尝试 这些解决方案也无济于事
  • 将Product.cs字段名称重命名为camelCase也没有帮助
这是我的密码

public class ElasticSearch
{
    private ElasticClient _client;

    public ElasticSearch()
    {
        var node = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(node);
        settings.DefaultIndex("logsystem.logs");
        _client = new ElasticClient(settings);
    }

    public void searchResults()
    {
        var searchResults = _client.Search<Product>(s => s.AllIndices());


    }
}
ElasticSearch中的映射:

{
"logsystem.logs": {
    "mappings": {
        "properties": {
            "Action": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "ActionName": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "MachineId": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "Name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "ProductLicenseKey": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    }
}
}
也许我的映射不对?任何答案都会有帮助。谢谢

编辑ElasticSearch文档通过邮递员获取:

{
"took": 11,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": {
        "value": 6,
        "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1ca2aaa6f1245cc38895",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Fixed Single Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1cb0aaa6f1245cc38896",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Fixed Multiple Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1cbdaaa6f1245cc38897",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Trackers Single Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1ccbaaa6f1245cc38898",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Trackers Multiple Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1cd3aaa6f1245cc38899",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Fixed Multiple Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1ce0aaa6f1245cc3889a",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Tree Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        }
    ]
 }
}

所以问题在于,客户机试图将camelCased JSON对象键反序列化到POCO属性,并且强制转换非常严格

解决方案: 创建ES客户端时,在连接设置上添加设置属性DefaultFieldNameInferrer

    public ElasticSearch()
    {
        var node = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(node);
        settings.DefaultIndex("logsystem.logs");
        settings.DefaultFieldNameInferrer(p => p);
        _client = new ElasticClient(settings);
    }

“你能发布弹性搜索中记录的样子吗?”VireshMathad在帖子中补充道。这就是我从PostmanI那里得到的,我想你应该检查“点击”而不是文档。@VireshMathad nahh same。。甚至找不到的字段。。。
    public ElasticSearch()
    {
        var node = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(node);
        settings.DefaultIndex("logsystem.logs");
        settings.DefaultFieldNameInferrer(p => p);
        _client = new ElasticClient(settings);
    }