Nest 在查询中将字段首字母转换为小写
Nest converts first letter of field to lowercase in query
我正在尝试将字典 更新到 elasticsearch,但键的第一个字母转换为小写字母。
the dictionary property in the entity
public Dictionary<string, Dictionary<string, string>> CurrentJson { get; set; }
public string CURRENT_JSON
{
set
{
CurrentJson = new Dictionary<string, Dictionary<string, string>>
{ { TableName.ToUpper(), JsonConvert.DeserializeObject<Dictionary<string, string>>(value) } };
}
}
我设置字典时的键是大写的。字母
upsert function
public async Task<T> Upsert(T document, string username = "N/A")
{
// check if name is duplicated
if (!await IsUniqueDocument(document))
throw new Exception("name duplicated");
PrepareDocument(document, username);
IndexRequest<T> request = new IndexRequest<T>(document, IndexName, TypeName, document.Id);
var response = await Client.IndexAsync<T>(request);
if (response.IsValid) return document;
// TODO: check thrown error
throw new Exception(response.Result.ToString());
}
注意:prepareDocument 函数不改变字典
看看NEST客户端的字段推理文档:https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/field-inference.html#camel-casing
If you’d like NEST to not change the casing of field names at all, simply pass a Func<string,string> to DefaultFieldNameInferrer that simply returns the input string
setup = WithConnectionSettings(s => s.DefaultFieldNameInferrer(p => p));
我正在尝试将字典
public Dictionary<string, Dictionary<string, string>> CurrentJson { get; set; }
public string CURRENT_JSON
{
set
{
CurrentJson = new Dictionary<string, Dictionary<string, string>>
{ { TableName.ToUpper(), JsonConvert.DeserializeObject<Dictionary<string, string>>(value) } };
}
}
我设置字典时的键是大写的。字母
upsert function
public async Task<T> Upsert(T document, string username = "N/A")
{
// check if name is duplicated
if (!await IsUniqueDocument(document))
throw new Exception("name duplicated");
PrepareDocument(document, username);
IndexRequest<T> request = new IndexRequest<T>(document, IndexName, TypeName, document.Id);
var response = await Client.IndexAsync<T>(request);
if (response.IsValid) return document;
// TODO: check thrown error
throw new Exception(response.Result.ToString());
}
注意:prepareDocument 函数不改变字典
看看NEST客户端的字段推理文档:https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/field-inference.html#camel-casing
If you’d like NEST to not change the casing of field names at all, simply pass a Func<string,string> to DefaultFieldNameInferrer that simply returns the input string
setup = WithConnectionSettings(s => s.DefaultFieldNameInferrer(p => p));