【发布时间】:2017-01-27 16:20:14
【问题描述】:
我有一些PageDocuments,我想根据标题进行搜索,不包括路径以某些特定文本开头的PageDocuments。分析该字段。我想要一些模糊性来帮助用户解决拼写错误。我需要能够进行部分匹配,所以some 将匹配some text 和this is some text。
如果我使用以下查询,由于 tf-idf,我不会得到完全匹配的第一个结果
{
"size": 20,
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/test/*"
}
}
}
]
}
}
}
然后我在title.not_analyzed 处添加了标题字段的not_analyzed 版本,并尝试使用term 添加函数分数以增加精确匹配的权重。
{
"query": {
"function_score": {
"functions": [
{
"weight": 2,
"filter": {
"fquery": {
"query": {
"term": {
"title.not_analyzed": {
"value": "myterm"
}
}
}
}
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/path/*"
}
}
}
]
}
},
"boost_mode": "multiply"
}
}
}
但这给了我相同的结果。我怎样才能得到最先返回的精确匹配?
【问题讨论】:
标签: elasticsearch