我正在尝试搜索以下文本:
“妇女持股”(注释中添加了“”以表示文字)
我从上面的文本中需要的是所有包含 flex 索引中存储的字段中包含“女性”和“持有”词的项目。
我试过的是:
string searchText = "women held";
var filterQuery = Query<T>.Terms("summaryText", searchText.Split(' '));
var result = Client.Search<T>(s => s.Index(IndexName).Query(filterQuery).Size(1000));
但是上面的查询结果导致从“summaryText”字段中获得“Women”或“holded”中的任何一个,但是我想要的是“Women and hold”,即两个文本都出现在“summaryText”字段中。
请让我知道这是否有意义。
我尝试了许多组合,但仍然没有成功。
Nest Guru的任何人都可以帮忙吗?
最佳答案
如果您要与字段上的“被关押的女人”完全匹配,请不要分割字符串:
string searchText = "women held";
var filterQuery = Query<T>.Terms("summaryText", searchText);
var result = Client.Search<T>(s => s.Index(IndexName).Query(filterQuery).Size(1000));
如果您要查找的是“包含”功能,则需要使用regexp查询(但是,如果您的数据量很大,则会产生性能开销):
SearchDescriptor<T> descriptor = new SearchDescriptor<T>();
descriptor = descriptor.Index(IndexName).Size(1000)
.Query(query => query
.Regexp(r => r.OnField("summaryText").Value(".*" + "woman held" + ".*")));
var result = ElasticClient().Search<T>(s => descriptor);
关于c# - 使用具有AND运算符的Nest ElasticSearch进行搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26741487/