Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nest DocumentExists()在其类型中使用通配符时失败_Nest_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Nest,elasticsearch" /> elasticsearch,Nest,elasticsearch" />

Nest DocumentExists()在其类型中使用通配符时失败

Nest DocumentExists()在其类型中使用通配符时失败,nest,elasticsearch,Nest,elasticsearch,使用类型通配符的Update()也存在这个问题,但我发现DocumentExists()也有同样的功能,所以我在这里总结了这个问题: 这很有效 var docExists = client.DocumentExists<object>(d => d .Index(indexname) .Id(myId) .Type("Abcdef")); var docExists=client.DocumentExists(d=>d .Index(索引名) .Id(

使用类型通配符的Update()也存在这个问题,但我发现DocumentExists()也有同样的功能,所以我在这里总结了这个问题:

这很有效

var docExists = client.DocumentExists<object>(d => d
    .Index(indexname)
    .Id(myId)
    .Type("Abcdef"));
var docExists=client.DocumentExists(d=>d
.Index(索引名)
.Id(myId)
.类型(“Abcdef”);
但这失败了

var docExists = client.DocumentExists<object>(d => d
    .Index(indexname)
    .Id(myId)
    .Type("Abc*"));
var docExists=client.DocumentExists(d=>d
.Index(索引名)
.Id(myId)
.类型(“Abc*”);
如果我完全省略类型,它也会失败。
有人知道怎么做吗?(即使不管文档的类型如何,它都可以正常工作。)

据我所知,无法在类型名称中指定通配符,但您可以使用一种技巧

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

var searchResponse = client.Search<dynamic>(s => s
    .Type(string.Empty)
    .Query(q => q.Term("id", 1))
    .Filter(f => f.Prefix("_type", "type")));
var searchResponse=client.Search(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; }
}
类程序
{
静态void Main(字符串[]参数)
{
var index name=“sampleindex”;
var uri=新的uri(“http://localhost:9200");
var settings=newconnectionsettings(uri).SetDefaultIndex(indexName).EnableTrace();
var客户端=新的ElasticClient(设置);
client.DeleteIndex(descriptor=>descriptor.Index(indexName));
CreateIndex(descriptor=>descriptor.Index(indexName));
client.Index(新的Type1{Id=1,Name=“Name1”},descriptor=>descriptor.Index(indexName));
client.Index(新的Type1{Id=11,Name=“Name2”},descriptor=>descriptor.Index(indexName));
client.Index(新的Type2{Id=1,City=“City1”},descriptor=>descriptor.Index(indexName));
client.Index(新的Type2{Id=11,City=“City2”},descriptor=>descriptor.Index(indexName));
client.Index(新的OtherType2{Id=1},descriptor=>descriptor.Index(indexName));
client.Refresh();
var searchResponse=client.Search(s=>s
.Type(string.Empty)
.Query(q=>q.Term(“id”,1))
.Filter(f=>f.Prefix(“_-type”,“type”));
var objects=searchResponse.Documents.ToList();
}
}
类别1
{
公共int Id{get;set;}
公共字符串名称{get;set;}
}
类别2
{
公共int Id{get;set;}
公共字符串City{get;set;}
}
类其他类型2
{
公共int Id{get;set;}
}

我不太了解你的大局,但也许你可以改变你的解决方案,使用索引而不是类型?您可以在索引名中添加通配符

顺便说一句:“fails”是指它的Exists属性设置为false。Type(string.Empy)表示什么?我只是想在elasticsearch请求中省略类型信息。