Here is the query I am using in it's entirety:
GET /property_index/_search
{
"from" : 0, "size" : 25,
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"nested" : {
"path" : "propertyNames",
"query" : {
"bool": {
"should": [
{
"match": {
"propertyNames.value": {
"query": "downing",
"operator": "and"
}
}
},
{
"match_phrase": {
"propertyNames.value": {
"query": "downing",
"slop": 100
}
}
},
{
"match_phrase_prefix" : {
"propertyNames.value" : {
"query" : "downing",
"max_expansions" : "500"
}
}
}
]
}
}
}
},
{
"nested" : {
"path": "propertyNames",
"boost": 1000,
"query": {
"bool": {
"must": [
{
"match": {
"propertyNames.type.raw": {
"query": "Primary Name"
}
}
},
{
"match_phrase": {
"propertyNames.value.raw": {
"query": "downing"
}
}
}
]
}
}
}
}
]
}
},
"boost": "5",
"functions": [
{
"filter": {
"bool": {
"must": [
{
"terms": {
"propertyType": [
"House",
"Flat",
"Bungalow",
"Mansion",
"Shed",
"Penthouse"
]
}
}
]
}
},
"weight": 44
},
{
"filter": {
"bool": {
"must_not": [
{
"terms": {
"area.propertyType": [
"House",
"Flat",
"Bungalow",
"Mansion",
"Shed",
"Penthouse"
]
}
}
]
}
},
"weight": 42
}
],
"max_boost": 42,
"score_mode": "max",
"boost_mode": "replace",
"min_score" : 0
}
},
"sort": [
{"status": { "order": "asc" }},
{"sortKey": { "order": "asc" }}
]
}
The part that I am adding is the second nested query in query.function_score.query.bool.should
. The data in propertyNames looks like this:
{
"names": [
{
"type": "Primary Name",
"value": "10 Downing Street"
},
{
"type": "Other Name",
"value": "The prime minister's house"
}
],
}
If, the search term was "downing", then the above document should get a higher score. If it was "prime", then it shouldn't be boosted.
However, the part that I have added is making no difference whatsoever.
I think that this is roughly correct. I have been playing around with lots of combinations of the should
s and must
s but no combination gives the correct results.
Am I along the right lines here?
It doesn't matter if the nested query that I have added is there or not. The same results are returned.
Would it help to see the mappings file?