如何使用nest client在弹性搜索中通过数组搜索数组属性 [英] How to search array property by array in elasticsearch with nest client
本文介绍了如何使用nest client在弹性搜索中通过数组搜索数组属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在让我说另外一个List值为1,3, 5,让我们说这个变量的名字是tosearch。
我想通过使用嵌套并找到一个匹配来搜索在弹性搜索索引中的acls类型记录lprop属性中的搜索值足够了。
例如:
`public class acls
{
public List< int> lprop {get; set;}
}
public void main()
{
// ..创建连接等..
//我们有3个rec的acls
// 1. lprop值:2,4,6,8
// 2. lprop值:1,9,0,4
// 3. lprop值:6 ,7,8
列表< int> tosearch = new int [] {1,3,5} .ToList();
//现在我想搜索acls lprop值中的搜索值。
//结果应该是:2.记录
}`
解决方案
使用 条款
查询
client.Search< acls>(s => s
.Query(q => q
.Terms(c => c
.Field(p => p.lprop )
.Terms< string>(tosearch)
)
)
);
Lets say we have a class called acls and this class has a List property called lprop.
Now lets say I have another List which has values 1,3,5 and lets say this variables name is tosearch.
I want to search tosearch values in acls typed records lprop property in an index of elasticsearch by using nest and finding only one match is sufficient.
Ex:
`public class acls
{
public List<int> lprop {get;set;}
}
public void main()
{
//.. creating connection and etc..
// we have 3 recs of acls
// 1. lprop values: 2,4,6,8
// 2. lprop values: 1,9,0,4
// 3. lprop values: 6,7,8
List<int> tosearch = new int[] { 1, 3, 5 }.ToList();
//Now I want to search tosearch values in acls lprop values.
// Result should be: 2. records
}`
解决方案
Use a Terms
query
client.Search<acls>(s => s
.Query(q => q
.Terms(c => c
.Field(p => p.lprop)
.Terms<string>(tosearch)
)
)
);
这篇关于如何使用nest client在弹性搜索中通过数组搜索数组属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文