Elasticsearch.net client can't do basic search

无人久伴 提交于 2019-12-04 08:59:18

If you use the low level client (elasticsearch.net) directly it will not do any normalisation and serialise the object verbatim:

var query = new { query = new { term = new { Name = "banana" } } };
var json = new ElasticsearchClient().Serializer.Serialize(query).Utf8String();

this will result to the following json:

{
  "query": {
    "term": {
      "Name": "banana"
    }
  }
}

If you use NEST the default behaviour is to camelCase property names (NEST is opinionated):

{
  "query": {
    "term": {
      "name": "banana"
    }
  }
}

If you use the low level client through the high level client (client.Raw) it will use the exact same serialisation settings as the high level client.

You can control this behaviour on the high level client through:

var connectionSettings = new ConnectionSettings()
    .SetDefaultPropertyNameInferrer(p=>p);
var client = new ElasticClient(connectionSettings);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!