【发布时间】:2017-09-13 21:31:14
【问题描述】:
我的索引是这样创建的:
'body' => [
'settings' => [
'analysis' => [
'filter' => [
'ngram_filter' => [
'type' => 'ngram',
'min_gram' => 2,
'max_gram' => 20,
],
],
'analyzer' => [
'ngram_analyzer' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'ngram_filter',
],
],
],
],
],
'mappings' => [
'doc' => [
'_all' => [
'type' => 'text',
'analyzer' => 'ngram_analyzer',
'search_analyzer' => 'standard',
],
'properties' => [
'pagetitle' => [
'type' => 'text',
'include_in_all' => true,
'term_vector' => 'yes',
'analyzer' => 'ngram_analyzer',
'search_analyzer' => 'standard',
],
'searchable_content' => [
'type' => 'text',
'include_in_all' => true,
'term_vector' => 'yes',
'analyzer' => 'ngram_analyzer',
'search_analyzer' => 'standard',
],
],
],
],
],
我会寻找这样的结果:
GET my_index/_search
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "Loesungen",
"fields": ["pagetitle^2", "searchable_content"],
"fuzziness": "AUTO"
}
},
"filter": {
"bool": {
"must": {
"term": {
"category.weight": 10
}
}
}
}
}
},
"size": 3,
"highlight": {
"fields": {
"pagetitle": {},
"searchable_content": {}
}
},
}
想要的效果:
- pagetitle 中包含 work 的文档比 searchable_content 中包含 word 的文档更重要
- 在 pagetitle 和 searchable_content 中都包含单词的文档比仅在 pagetitle 中包含该单词的文档更重要
但是当我搜索时,我得到的结果是这样的:
{
"highlight": {
"pagetitle": [
"<em>Lösungen</em>"
]
},
"_score": 470.29608,
}, {
"highlight": {
"searchable_content": [
"text <em>Lösungen</em> text"
],
"pagetitle": [
"<em>Lösungen</em>"
]
},
"_score": 441.84506
}
因此,您看到标题中仅包含单词的文档比标题和内容中包含该单词的文档得分更高。
问题是 - 应该进行哪些更改才能使其按我描述的那样工作?在查询中创建索引或其他内容?
【问题讨论】:
标签: elasticsearch