【发布时间】:2018-04-05 11:22:33
【问题描述】:
我想按以下顺序搜索文本并相应地给出相关性分数:
- 匹配准确的词组
- 所有字词(确切字词)都应出现在搜索结果中
- 结果中应出现一些或至少一个词
这是我的查询:
{
"_source": [
"title"
],
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "introduction to java",
"fuzziness": 0,
"operator": "and",
"boost": 1
}
}
},
{
"match_phrase": {
"title": {
"query": "introduction to java",
"boost": 5
}
}
}
],
"minimum_should_match": 1
}
},
"size": 20
}
但我首先得到的是 Javascript 或 jQuery 而不是 java。 结果:
{
"_score": 594.7316,
"_source": {
"title": "Introduction to jQuery Web Development"
}
}
,
{
"_score": 592.86993,
"_source": {
"title": "Introduction to JavaScript Development"
}
}
,
{
"_score": 592.8397,
"_source": {
"title": "A Comprehensive Introduction to Java Virtual Machine (JVM)"
}
}
,
{
"_score": 591.7474,
"_source": {
"title": "Introduction to Java for Programmers"
}
}
我应该怎么做才能做到这一点?提前致谢。
【问题讨论】:
-
您的查询对我来说很好 - 除了使用
"operator": "and"会破坏您的第三条规则,即包含至少包含其中一个术语的结果(将其更改为“或”或只是删除它)。也许可以尝试使用Explain 选项来查看您的结果是如何评分的。 -
解释选项很好。我得到了一些东西:“描述”:“重量(标题:”(我在 int intr intro introd introdu introduc introduct introducti introductio Introduction)(t to)(j ja jav java)”在 5759)[PerFieldSimilarity],结果:”它在这里搜索任何一个边缘 ngram。但我这里没有使用任何 ngram 分析器
标签: elasticsearch