2017-07-26 155 views
0

我的问题是,如何使用NEST(c#)在渗透函数中使用像multimatch,slop和fuzziness这样的搜索选项?Elasticsearch percolate函数中的搜索选项

我想要实现返回完全以下搜索功能的相反结果的渗滤液功能:

public List<string> search(string query){ 
....... 
....... 
var searchResponse = client.Search<Document>(s => s 
       .AllTypes() 
        .From(0) 
        .Take(10) 
       .Query(q => q    // define query 
        .MultiMatch(mp => mp   // of type MultiMatch 
        .Query(input.Trim()) 
        .Fields(f => f   // define fields to search against 
        .Fields(f3 => f3.doc_text)) 
        .Slop(2) 
        .Operator(Operator.And) 
        .Fuzziness(Fuzziness.Auto)))); 
} 

以下是渗滤液功能我目前使用的,但不知道如何将multimatch,污和模糊选项。我在文档中找不到关于此的详细信息。

var searchResponseDoc = client.Search<PercolatedQuery>(s => s 
       .Query(q => q 
       .Percolate(f => f 
       .Field(p => p.Query) 
       .DocumentType<Document>() //I have a class called Document 
       .Document(myDocument))) // myDocument is an object of type Document 

谢谢。

回答

2

在第一个你正在做的multi_match查询有你需要的选项。在后者中,您执行percolator查询。

如果你想两者都做,你可以使用二进制和位运算符e.g

.Query(q => 
    !q.MultiMatch(mp => mp 
     .Query(input.Trim()) 
     .Fields(f => f.Fields(f3 => f3.doc_text)) 
     .Slop(2) 
     .Operator(Operator.And) 
     .Fuzziness(Fuzziness.Auto) 
    ) 
    && q.Percolate(f => f 
      .Field(p => p.Query) 
      .DocumentType<Document>() 
      .Document(myDocument) 
    ) 
) 

不使用&&创建bool查询与这两个查询为must条款。一元运算符!通过将查询包装在bool中并将查询置于must_not子句中来取消查询。

查看更多信息https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-queries.html

https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/bool-queries.html

+0

非常感谢您的回复。不,我不想做这两个,我想要一个可以考虑模糊和倾斜的过滤器; Elasticsearch有可能吗? – Abdulaziz