我正在使用elasticsearch,并且有一段时间要进行精确匹配。我尝试了 match、query_string 等的各种组合,但要么一无所获,要么结果不好。查询如下所示:
{
"filter": {
"term": {
"term": "dog",
"type": "main"
}
},
"query": {
"match_phrase": {
"term": "Dog"
}
},
"sort": [
"_score"
]
}
排序结果
10.102211 {u'term': u'The Dog', u'type': u'main', u'conceptid': 7730506}
10.102211 {u'term': u'That Dog', u'type': u'main', u'conceptid': 4345664}
10.102211 {u'term': u'Dog', u'type': u'main', u'conceptid': 144}
7.147442 {u'term': u'Dog Eat Dog (song)', u'type': u'main', u'conceptid': u'5288184'}
我当然看到“The Dog”、“That Dog”和“Dog”都有相同的分数,但我需要弄清楚如何提高精确匹配“Dog”的分数。
我也试过
{
"sort": [
"_score"
],
"query": {
"bool": {
"must": [
{
"match": {
"term": "Dog"
}
},
{
"match_phrase": {
"term": {
"query": "Dog",
"boost": 5
}
}
}
]
}
},
"filter": {
"term": {
"term": "dog",
"type": "main"
}
}
}
但这仍然给了我
11.887239 {u'term': u'The Dog', u'type': u'main', u'conceptid': 7730506}
11.887239 {u'term': u'That Dog', u'type': u'main', u'conceptid': 4345664}
11.887239 {u'term': u'Dog', u'type': u'main', u'conceptid': 144}
8.410372 {u'term': u'Dog Eat Dog (song)', u'type': u'main', u'conceptid': u'5288184'}