I want to search text in the following order and give relevence score accordingly:
- match for exact phrase
- All words (exact word) should appear in search result
- some or atleast one word should appear in result
Here is my query:
{
"_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
}
But I am getting Javascript or jQuery first instead of java. Result:
{
"_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"
}
}
What should I do to make this happen ? Thanks in advance.
"operator": "and"
will break your third rule of including results that contain at least one of the terms in it (change it to "or" or just remove it). Maybe try using the Explain option to see how your results are being scored. – tchambers