如何将过滤器查询写入嵌套程序

How to write a percolator query to nest program

我在弹性搜索中有一个过滤器查询,如下所示。

put /skill-index

PUT /skill-index/skill-type/_mapping
{
    "properties" : {
        "message" : {
            "type": "string"
        }

    }

}

PUT /skill-index/.percolator/101
{
    "query" : {
        "match" : {
            "message" : "crossstitch"
        }
    }

}

PUT /skill-index/.percolator/102
{
    "query" : {
        "match" : {
            "message" : "chainstitch"
        }
    }

}

PUT /skill-index/.percolator/103
{
    "query" : {
        "match" : {
            "message" : "stemstitch"
        }
    }

}

PUT /skill-index/.percolator/104
{
    "query" : {
        "match" : {
            "message" : "longandshort"
        }
    }

}



GET /skill-index/skill-type/_percolate  
{
    "doc" : {
        "message" : "Know chainstitch and stemstitch"
    }
}

现在,我想在我的 NEST 程序中使用 GET 查询。 例如。我有一个名为 skillentity 的实体。我将传递一个可变字符串,例如 "Know chainstitch and stemstitch".

我想检索值 102,103

所以我应该构建类似 声明一个列表 列表技能列表=新列表

之后我想要一个 lambda 表达式查询,比如。

var skillsList = client.Percolate(......传递变量并得到结果..)

你能帮我在 NEST 中构建查询吗

这个例子将解释如何在 NEST 中处理过滤器

internal class Program
{
    private static void Main(string[] args)
    {
        var indexName = "indexname";

        var uri = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(uri)
            .SetDefaultIndex(indexName)
            .EnableTrace();
        var client = new ElasticClient(settings);

        var indicesResponse = client.DeleteIndex(descriptor => descriptor.Index(indexName));

        client.CreateIndex(descriptor => descriptor.Index(indexName).AddMapping<Document>(m => m.MapFromAttributes()));

        var percolate = client.RegisterPercolator<Document>("p1",
            descriptor => descriptor.Index(indexName).Query(q => q.Match(m => m.OnField(f => f.Name).Query("test"))));

        var percolate2 = client.RegisterPercolator<Document>("p2",
            descriptor => descriptor.Index(indexName).Query(q => q.Match(m => m.OnField(f => f.Name).Query("something"))));

        var percolateResponse =
            client.Percolate<Document>(descriptor => descriptor.Index(indexName).Document(new Document {Name = "this is a test"}));

        //Matches contain percolator p1 
        var percolatorIds = percolateResponse.Matches.Select(x => x.Id);

        Console.ReadKey();
    }
}

public class Document
{
    public int Id { get; set; }
    public string Name { get; set; }
}