Let's say my index has name and skills.
{
"name": "Vishnu Prasad",
"skills": ["devops", "ruby"]
}
{
"name": "Prasad",
"skills": ["ruby"]
}
{
"name": "Jonathan",
"skills": ["devops"]
}
{
"name": "Vishnu Prasad A D",
"skills": ["devops", "nodejs"]
}
{
"name": "Vishnu",
"skills": ["devops"]
}
{
"name": "Vishnu Dinakaran",
"skills": ["devops"]
}
My criteria are,
field | weight |
---|---|
name | 10 |
--------------------- | ------------------ |
skills | 9 |
--------------------- | ------------------ |
field3 | 8 |
--------------------- | ------------------ |
When I search for name: Vishnu Prasad
and skill: devops
, the results should be based on the weight.
If both of the field matches, then it should come first. Also, the score should be more for phrase matches. i.e "Vishnu Prasad" should appear before "Vishnu".
I have written the following query but it is not giving me in the order that I need.
GET test/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"name": {
"query": "Vishnu Prasad",
}
}
},
{
"match": {
"skills": {
"query": "devops",
}
}
}
]
}
}
],
"should": [
{
"match_phrase": {
"name": {
"query": "Vishnu Prasad",
"boost": 10
}
}
},
{
"match_phrase": {
"skills": {
"query": "devops",
"boost": 9
}
}
}
]
}
}
}
The order that I need is,
{
"name": "Vishnu Prasad",
"skills": ["devops", "ruby"]
}
{
"name": "Vishnu Prasad A D",
"skills": ["devops", "nodejs"]
}
{
"name": "Vishnu Dinakaran",
"skills": ["devops"]
}
{
"name": "Vishnu",
"skills": ["devops"]
}
{
"name": "Jonathan",
"skills": ["devops"]
}
{
"name": "Prasad",
"skills": ["ruby"]
}