如何使用 NEST v6 进行渗透
How to use NEST v6 to percolate
如何使用 ES 的过滤器功能将传入文档与我的查询进行匹配?
我的查询是 "biggest winner"
我使用的是 ES v6 和相同版本的 NEST 库。
这是我的class
public class PercolatedQuery
{
public string Subject { get; set; }
public string Body { get; set; }
public string URL { get; set; }
public DateTime? Date { get; set; }
public QueryContainer Query { get; set; }
}
这是我的设置
Uri node = new Uri("http://localhost:9200/");
this.Settings = new ConnectionSettings(node)
.DisableDirectStreaming()
.DefaultIndex("mytestIndex");
this.Client = new ElasticClient(this.Settings);
if (!this.Client.IndexExists("mytestIndex").Exists)
{
this.Client.CreateIndex("mytestIndex", c => c
.Settings(s => s
.NumberOfShards(1)
.NumberOfReplicas(0)
)
.Mappings(m => m
.Map<PercolatedQuery>(mm => mm
.AutoMap()
.Properties(p => p
// map the query field as a percolator type
.Percolator(pp => pp
.Name(n => n.Query)
)
)
)
)
);
this.Client.Alias(a => a
.Add(add => add
.Index("mytestIndex")
.Alias("testAlias")
));
}
我必须保存查询,然后才能搜索文档
PercolatedQuery documentQuery = new PercolatedQuery
{
Id = "PercolatedQuery",
Query = new MatchQuery
{
Field = Infer.Field<PercolatedQuery>(entry => entry.Body),
Query = "healthcare biggest"
}
};
Client.Index(documentQuery,
d => d.Index("mytestIndex").Refresh(Refresh.WaitFor));
PercolatedQuery document1 = new PercolatedQuery { Body = "healthcare biggest winner" };
Client.Search<PercolatedQuery>(s => s
.Query(q => q
.Percolate(p => p
.Field(f => f.Query)
.Document(document1)
)
)
);
如何使用 ES 的过滤器功能将传入文档与我的查询进行匹配? 我的查询是 "biggest winner"
我使用的是 ES v6 和相同版本的 NEST 库。
这是我的class
public class PercolatedQuery
{
public string Subject { get; set; }
public string Body { get; set; }
public string URL { get; set; }
public DateTime? Date { get; set; }
public QueryContainer Query { get; set; }
}
这是我的设置
Uri node = new Uri("http://localhost:9200/");
this.Settings = new ConnectionSettings(node)
.DisableDirectStreaming()
.DefaultIndex("mytestIndex");
this.Client = new ElasticClient(this.Settings);
if (!this.Client.IndexExists("mytestIndex").Exists)
{
this.Client.CreateIndex("mytestIndex", c => c
.Settings(s => s
.NumberOfShards(1)
.NumberOfReplicas(0)
)
.Mappings(m => m
.Map<PercolatedQuery>(mm => mm
.AutoMap()
.Properties(p => p
// map the query field as a percolator type
.Percolator(pp => pp
.Name(n => n.Query)
)
)
)
)
);
this.Client.Alias(a => a
.Add(add => add
.Index("mytestIndex")
.Alias("testAlias")
));
}
我必须保存查询,然后才能搜索文档
PercolatedQuery documentQuery = new PercolatedQuery
{
Id = "PercolatedQuery",
Query = new MatchQuery
{
Field = Infer.Field<PercolatedQuery>(entry => entry.Body),
Query = "healthcare biggest"
}
};
Client.Index(documentQuery,
d => d.Index("mytestIndex").Refresh(Refresh.WaitFor));
PercolatedQuery document1 = new PercolatedQuery { Body = "healthcare biggest winner" };
Client.Search<PercolatedQuery>(s => s
.Query(q => q
.Percolate(p => p
.Field(f => f.Query)
.Document(document1)
)
)
);