Elasticsearch - 默认字段名称推断器
Elasticsearch - Default Field Name Inferrer
在 nest 的 2.0 alpha 中,我正在努力将 DefaultFieldNameInferrer
设置为驼峰式。
在弄清楚如何查看 'request body' 之后(通过明确地将 DisableDirectStreaming
设置为 true,尽管默认值为 true...),我可以看到这样的请求:
...fil.Bool(b2 => b2.Must(m => m.Term(t => t.DomainName, host))))...
正在发送 DomainName
大写 D
:
...{"term":{"DomainName":{"value":"example.com"}}}]}...
1.7 版总是发送驼峰式,因此我的映射都是驼峰式。
如何将其改回驼峰式?
编辑
连接:
ElasticClient = new ElasticClient
(new ConnectionSettings(new Uri(WebConfigMethods.GetElasticSearchUri())).MapDefaultTypeIndices
(new ElasticsearchMethods().ElasticSearchDefaultTypeIndices)
.DisableDirectStreaming(true)
.DefaultFieldNameInferrer
(s =>
{
if (string.IsNullOrEmpty(s))
return s;
if (!char.IsUpper(s[0]))
return s;
string camelCase = char.ToLower(s[0], CultureInfo.InvariantCulture)
.ToString(CultureInfo.InvariantCulture);
if (s.Length > 1)
camelCase += s.Substring(1);
return camelCase;
}));
要求:
var result = elasticClient.Search<ADocType>
(s => s.Take(1)
.Query
(qu =>
qu.Bool
(b => b.Filter(fil => fil.Bool(b2 => b2.Must(m => m.Term(t => t.DomainName, host)))))));
巢实际发送的内容:
{"size":1,"query":{"bool":{"filter":[{"bool":{"must":[{"term":{"DomainName":{"value":"example.com"}}}]}}]}}}
只需添加此作为参考,以防以后有人偶然发现这个问题。
查看 'Mpdreamz' 评论。
I see two options:
implement a subclass of our JsonNetSerailizer that returns what you need for CreatePropertyName
Add a hook at the beginning of the resolve cascading flow. e.g another func on connectionsettings.
在 nest 的 2.0 alpha 中,我正在努力将 DefaultFieldNameInferrer
设置为驼峰式。
在弄清楚如何查看 'request body' 之后(通过明确地将 DisableDirectStreaming
设置为 true,尽管默认值为 true...),我可以看到这样的请求:
...fil.Bool(b2 => b2.Must(m => m.Term(t => t.DomainName, host))))...
正在发送 DomainName
大写 D
:
...{"term":{"DomainName":{"value":"example.com"}}}]}...
1.7 版总是发送驼峰式,因此我的映射都是驼峰式。
如何将其改回驼峰式?
编辑
连接:
ElasticClient = new ElasticClient
(new ConnectionSettings(new Uri(WebConfigMethods.GetElasticSearchUri())).MapDefaultTypeIndices
(new ElasticsearchMethods().ElasticSearchDefaultTypeIndices)
.DisableDirectStreaming(true)
.DefaultFieldNameInferrer
(s =>
{
if (string.IsNullOrEmpty(s))
return s;
if (!char.IsUpper(s[0]))
return s;
string camelCase = char.ToLower(s[0], CultureInfo.InvariantCulture)
.ToString(CultureInfo.InvariantCulture);
if (s.Length > 1)
camelCase += s.Substring(1);
return camelCase;
}));
要求:
var result = elasticClient.Search<ADocType>
(s => s.Take(1)
.Query
(qu =>
qu.Bool
(b => b.Filter(fil => fil.Bool(b2 => b2.Must(m => m.Term(t => t.DomainName, host)))))));
巢实际发送的内容:
{"size":1,"query":{"bool":{"filter":[{"bool":{"must":[{"term":{"DomainName":{"value":"example.com"}}}]}}]}}}
只需添加此作为参考,以防以后有人偶然发现这个问题。
查看 'Mpdreamz' 评论。
I see two options:
implement a subclass of our JsonNetSerailizer that returns what you need for CreatePropertyName
Add a hook at the beginning of the resolve cascading flow. e.g another func on connectionsettings.