在查询

时间:2016-10-19 18:23:44

标签: elasticsearch nest

我可以用ElasticSearch和NEST执行多匹配搜索,我可以在查询中使用布尔运算传递查询吗?看来我传递给multimatch的所有术语都默认与OR链接(可以更改为其他运算符)。

我希望ES从查询中评估布尔运算符,例如。 “A&& B || C”和相同的搜索多个字段。

2 个答案:

答案 0 :(得分:1)

是的,你可以JavaMail doesn't support JavaME

{
  "multi_match" : {
    "query":      "Will Smith",
    "type":       "best_fields",
    "fields":     [ "first_name", "last_name" ],
    "operator":   "and" 
  }
}

答案 1 :(得分:1)

您可以设置operator to and来更改multi_match query的语义。以NEST为例

void Main()
{
    var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
    var connectionSettings = new ConnectionSettings(pool);

    var client = new ElasticClient(connectionSettings);

    client.Search<MyDocument>(s => s
        .Query (q => q
            .MultiMatch(m => m
                .Fields(f => f
                    .Field(p => p.FirstProperty)
                    .Field(p => p.SecondProperty)
                )
                .Query("this is the query")
                .Operator(Operator.And)
            )
        )
    );
}

public class MyDocument
{
    public string FirstProperty { get; set; }

    public string SecondProperty { get; set; }
}

生成以下查询

{
  "query": {
    "multi_match": {
      "query": "this is the query",
      "operator": "and",
      "fields": [
        "firstProperty",
        "secondProperty"
      ]
    }
  }
}

另请查看MultiMatch query usage docs for NEST