【发布时间】:2020-03-03 17:50:15
【问题描述】:
我提取了这种简化格式的文档:
public class Document
{
public string Id { get; set; }
}
我可以使用这个循环/滚动所有文档:
client.Search<Document>
(
scr => scr.Index(IndexName)
.From(0)
.Size(100)
.MatchAll()
.Scroll(scrollTimeout)
)
;
是否可以只关注 ID 以特定字符串结尾的文档 - 例如:bla?
我试过了:
return client.Search<Document>
(
scr => scr.Index(IndexName)
.From(0)
.Size(100)
.MatchAll()
.Scroll(scrollTimeout).Query(q => q
.Match(m => m
.Field(f => f.Id)
.Query("bla")
)
)
)
;
也试过了:
return client.Search<Document>
(
scr => scr.Index(IndexName)
.From(0)
.Size(100)
.MatchAll()
.Scroll(scrollTimeout).Query(q => q
.MoreLikeThis(sn => sn
.Fields(ff => ff
.Field(f => f.Id)
)
使用通配符也不起作用:
return client.Search<Document>
(
scr => scr.Index(IndexName)
.From(0)
.Size(100)
.MatchAll()
.Scroll(scrollTimeout).Query(q => q
.Wildcard(c => c
.Name("named_query")
.Boost(1.1)
.Field(p => p.Id)
.Value("bla")
.Rewrite(MultiTermQueryRewrite.TopTermsBoost(10))
)
)
)
;
请注意,这适用于其他字段。所以我目前的预感是,这样的事情对 Id 不起作用。
Filip Cordas 建议使用正则表达式。这也不起作用:
return client.Search<Document>
(
scr => scr.Index(IndexName)
.From(0)
.Size(1000)
.MatchAll().Scroll(scrollTimeout).Query(q => q
.Regexp(c => c
.Field(p => p.Id)
.Value("bla$")
)
)
)
;
应 Russ Cam 的要求。我尝试了以下方法,但也没有用:
var searchResponses = client.Search<Document>
(
scr => scr.Index(indexName)
.From(0)
.Size(1000)
.Query(q => q.Regexp(c => c
.Field(p => p.Id)
.Value("bla$")
)
)
)
;
【问题讨论】:
-
谢谢。尝试了这个但很挣扎 - 得到错误的请求错误。你能建议代码吗?
-
这可能更有用,还包括一个例子elastic.co/guide/en/elasticsearch/reference/current/…
-
试试 .Query("*bla")
-
这不起作用...
标签: c# elasticsearch nest