弹性NEST中的动态查询

时间:2018-02-20 11:36:34

标签: c# elasticsearch nest

所以我在NEST中手动构建了以下查询,它可以正常工作, 我试图弄清楚的是一种根据产品规格过滤器传递的动态构建它的方法

function delete_Callback(hObject, eventdata, handles)
cam = handles.cam;
delete (cam);
clear cam;
guidata(hObject, handles);

在查看Russ分享的链接后,我认为解决方案是传递我的过滤器

.Query(q => q                
            .MultiMatch(m => m
                .Query(searchBox.Text + "*")
                .Fields(ff => ff
                    .Field(f => f.Name, boost: nameBoost)
                    .Field(f => f.Description, boost: descriptionBoost)
                    .Field(f => f.ProductCode)))
        && q.Nested(n => n
            .Path(p => p.ProductSpecification)
            .Query(q2 => q2                   
                .Terms(t => t
                    .Field(f => f.ProductSpecification.Suffix("name"))
                    .Terms("Guarantee")
                    )).Query(q3 => q3
                        .Terms(t2 => t2
                            .Field(f2 => f2.ProductSpecification.Suffix("value"))
                            .Terms("3 years")
                            )))
        && q.Nested(n => n
            .Path(p => p.ProductSpecification)
            .Query(q2 => q2
                .Terms(t => t
                    .Field(f => f.ProductSpecification.Suffix("name"))
                    .Terms("Brand")
                    )).Query(q3 => q3
                        .Terms(t2 => t2
                            .Field(f2 => f2.ProductSpecification.Suffix("value"))
                            .Terms("Sony")
                            )))

这会给我一些名称,例如"保证"和价值如" 2年,3年"查看Russ链接的代码我可以让他运行我的过滤器列表并吐出布尔过滤器,但我想我需要这个来构建一个嵌套查询?

public class ElasticJsonFilter
{
    public string name { get; set; }
    public List<string> Values { get; set; } = new List<string>();
}

0 个答案:

没有答案
相关问题