我在记录中为匹配类别和名称编写了一个Elaticsearch查询。
我的样本记录:
{category: "disease", name: "Heart Diseases", dui: "D006331", url_name: "Heart Disease"}
我需要将我的参数与' name'匹配。和类别应该是'疾病'和'医院'总是这样写:
match: {
name: {
query: searchString,
fuzziness: 2,
operator: "or"
},
category: ['hospital', 'disease']
}
更新的代码:
client.search({
index: 'xpertdox',
type: 'disease',
size: 20,
body: {
query: {
bool: {
must: {
match: {
name: {
query: req.param('disease'),
//fuzziness:"AUTO",
fuzziness: 2,
operator: "or"
}
}
},
should : [
{ term : { category: disease} }
],
minimum_should_match: 2
}
}
但这不起作用。我不知道错误在哪里。
答案 0 :(得分:0)
要匹配所有类别,请使用下面的一个doc使用查询
minimum_should_match
filter
应该等于可选子句的数量("中的子句应该"数组)。
<强>更新强>
要匹配类别列表中的一个类别,请使用terms
和{
"query": {
"bool": {
"must": {
"match": {
"name": {
"query": searchString,
"fuzziness": 2,
"operator": "or"
}
}
},
"filter": {
"terms": { "category": [ "hospital", "disease"] }
}
}
}
}
查询
firebase deploy --only functions