【发布时间】:2016-10-19 18:23:43
【问题描述】:
我能否使用 ElasticSearch 和 NEST 执行多重匹配搜索,以在查询中使用布尔运算传递查询?看来我传递给 multimatch 的所有术语默认都与 OR 链接(可以更改为其他运算符)。
我希望 ES 从查询中评估布尔运算符,例如。 "A && B || C" 和多个字段一样搜索。
【问题讨论】:
标签: elasticsearch nest
我能否使用 ElasticSearch 和 NEST 执行多重匹配搜索,以在查询中使用布尔运算传递查询?看来我传递给 multimatch 的所有术语默认都与 OR 链接(可以更改为其他运算符)。
我希望 ES 从查询中评估布尔运算符,例如。 "A && B || C" 和多个字段一样搜索。
【问题讨论】:
标签: elasticsearch nest
{
"multi_match" : {
"query": "Will Smith",
"type": "best_fields",
"fields": [ "first_name", "last_name" ],
"operator": "and"
}
}
【讨论】:
您可以设置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"
]
}
}
}
【讨论】: