栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

当在通配符类型中使用通配符时,DocumentExists()失败

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

当在通配符类型中使用通配符时,DocumentExists()失败

据我所知,不可能在类型名称中指定通配符,但是您可以做一些技巧。

您可以在索引中查询具有特定ID的文档,并使用前缀过滤器来缩小对某些类型的搜索范围。

var searchResponse = client.Search<dynamic>(s => s    .Type(string.Empty)    .Query(q => q.Term("id", 1))    .Filter(f => f.Prefix("_type", "type")));

这是完整的示例:

class Program{    static void Main(string[] args)    {        var indexName = "sampleindex";        var uri = new Uri("http://localhost:9200");        var settings = new ConnectionSettings(uri).SetDefaultIndex(indexName).EnableTrace();        var client = new ElasticClient(settings);        client.DeleteIndex(descriptor => descriptor.Index(indexName));        client.CreateIndex(descriptor => descriptor.Index(indexName));        client.Index(new Type1 {Id = 1, Name = "Name1"}, descriptor => descriptor.Index(indexName));        client.Index(new Type1 {Id = 11, Name = "Name2"}, descriptor => descriptor.Index(indexName));        client.Index(new Type2 {Id = 1, City = "City1"}, descriptor => descriptor.Index(indexName));        client.Index(new Type2 {Id = 11, City = "City2"}, descriptor => descriptor.Index(indexName));        client.Index(new OtherType2 {Id = 1}, descriptor => descriptor.Index(indexName));        client.Refresh();        var searchResponse = client.Search<dynamic>(s => s .Type(string.Empty) .Query(q => q.Term("id", 1)) .Filter(f => f.Prefix("_type", "type")));        var objects = searchResponse.documents.ToList();    }}class Type1{    public int Id { get; set; }    public string Name { get; set; }}class Type2{    public int Id { get; set; }    public string City { get; set; }}class OtherType2{    public int Id { get; set; }}

对全局没有太多了解,但是也许您可以更改解决方案以使用索引而不是类型?您可以将通配符放在索引名称中。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403697.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号