弹性搜索NEST库,有线行为 [英] Elasticsearch NEST library, wired behavior

查看:170
本文介绍了弹性搜索NEST库,有线行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var result = client.Search< StudenntBrief>(s => ; s.Type(Students)。Query(q => q.Term(Name,Robert))); 

它工作正常,得到7个结果。



而不是使用maigic字符串表示字段我试图使用表达式如下。

  var result = client.Search< StudenntBrief> ;(s => s.Type(Students)。Query(q => q.Term(t => t.Name,Robert))); 

我发现零结果。



另外一个例子。



工作。

  var result = client 。搜索< StudenntBrief>(s => s.Type(Students)。Query(q => q.MultiMatch(a => a.OnFields(new List< string {Name})Query 罗伯特)))); 

无效。

  var result = client.Search< StudenntBrief>(s => s.Type(Students)查询(q => q.MultiMatch(a => a.OnFields => f.Name).Query(Robert)))); 

我想知道为什么使用表达式查询表示字段不起作用。

解决方案

bsarkar的答案部分正确。



NEST camel默认情况下字段名称。您可以通过指定自己的属性名称推断器来覆盖默认的camelCase:如何禁用骆驼套装NEST中的弹性搜索字段名称。这种方法将适用于所有字段和所有类型。



另一种方法是使用 ElasticyProperty 属性为bsarkar,或使用版本1.3中添加的较新的流畅属性映射API: https://github.com/elasticsearch/elasticsearch-net/pull/1062

 设置。 MapPropertiesFor< MyClass>(props =>道具
.Rename(p => p.Foo,bar)
);

希望有所帮助。


Using NEST .NET library I worte following query.

var result = client.Search<StudenntBrief>(s => s.Type("Students").Query(q => q.Term("Name","Robert")));

It worked fine and got 7 results.

Instead of using maigic string to represent field i tried to use expression as follows.

var result = client.Search<StudenntBrief>(s => s.Type("Students").Query(q => q.Term(t => t.Name,"Robert")));

I found zero results.

Here is one more example.

Works.

var result = client.Search<StudenntBrief>(s => s.Type("Students").Query(q => q.MultiMatch(a => a.OnFields(new List<string{"Name"}).Query("Robert"))));

Doesn't works.

var result = client.Search<StudenntBrief>(s => s.Type("Students").Query(q => q.MultiMatch(a => a.OnFields(f=> f.Name).Query("Robert"))));

I am wondering why query using expression to represent field is not working.

解决方案

bsarkar's answer is partially correct.

NEST camelCases field names by default. There are a few ways to customize this behavior.

You can override the default camelCasing by specifying your own property name inferrer: How to disable camel casing Elasticsearch field names in NEST?. This approach will apply to all fields and all types.

Another approach is to specify the field names explicitly by either using the ElasticyProperty attribute as bsarkar mentioned, or using the newer fluent property mapping API that was added in version 1.3: https://github.com/elasticsearch/elasticsearch-net/pull/1062

settings.MapPropertiesFor<MyClass>(props => props
    .Rename(p => p.Foo, "bar")
);

Hope that helps.

这篇关于弹性搜索NEST库,有线行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆