Filter not working for weighted search - elasticsearch

I am pretty new to elasticsearch and have not really got the hold of it. So I have a search, the results of which will be weighed according to the weight of their tags, which works absolutely fine, but later when I introduced a filter, the search always gives me empty results. Here is what I have tried:
{
"nested": {
"path": "tags",
"score_mode": "sum",
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"match_phrase_prefix": {
"tags.tag": "big"
}
}
],
"filter": {
"term": {
"type.primary": "audio"
}
}
}
},
"field_value_factor": {
"field": "tags.weight"
},
"boost_mode": "multiply",
"boost": 10
}
}
}
}
The example result with the filter should be something like this:
{
"_index": "assets",
"_type": "Asset",
"_id": "5a1dc3c0848662ee49e36f43s",
"_score": 886.8744,
"_source": {
"name": "And Action Breakbeat",
"meta_data": {
"type": "audio/mp3",
"file_name": "music_zapsplat_and_action_breakbeat.mp3"
},
"file_key": "music_zapsplat_and_action_breakbeat.mp3",
"src": {
"url": "https://exapmle.com/music_zapsplat_and_action_breakbeat.mp3"
},
"type": {
"primary": "AUDIO",
"secondary": "mp3"
},
"thumbnail_url": "https://example.com/thumbnail/audio.jpg",
"tags": [
{
"tag": "big",
"weight": 10
},
{
"tag": "beat",
"weight": 5
},
{
"tag": "music",
"weight": 3.3333333333333335
}
],
"isDeleted": false,
}
}
Thank you!

You cannot match type.primary inside a nested query for tags. Try this query instead:
{
"query": {
"bool": {
"filter": {
"term": {
"type.primary": "audio"
}
},
"must": [
{
"nested": {
"path": "tags",
"query": {
"function_score": {
"query": {
"match_phrase_prefix": {
"tags.tag": "big"
}
},
"field_value_factor": {
"field": "tags.weight"
},
"score_mode": "sum",
"boost_mode": "multiply",
"boost": 10
}
}
}
}
]
}
}
}

Related

ElasticSearch DSL: query on custom tags too

I'm new to ES, but already have a basic query that I need to extend.
The query is currently doing a search based on keywords and also on geo-distance.
Now, I have added a custom tag into my index, and I wish to take it into account too.
I wish to filter and score my results based on the imageTags (tag + score)!
PS: I have seen other similar posts, but I can't figure out how to adapt my query (none of my attempts work).
Here is my query:
GET /posts_index/_search
{
"track_total_hits": true,
"from":0,
"size":10,
"_source": [
"id",
"tags",
"taxonomies",
"storesNames",
"geoLocations",
"storesIds",
"imageUri"
],
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"distance_feature": {
"field": "geoLocations",
"pivot": "10km",
"origin": [
-71.3,
41.15
]
}
},
{
"distance_feature": {
"field": "creationTime",
"pivot": "14d",
"origin": "now"
}
},
{
"query_string": {
"fields": [
"tags^3",
"taxonomies^5"
],
"query": "",
"fuzziness": "auto"
}
},
]
}
},
"functions": [
{
"script_score": {
"script": {
"source": "Math.sqrt(doc['commentsCount'].value)"
}
}
},
{
"script_score": {
"script": {
"source": "Math.log(2 + doc['likesCount'].value)"
}
}
},
{
"script_score": {
"script": {
"source": "Math.log(2 + doc['viewsCount'].value)"
}
}
}
],
"score_mode": "avg"
}
}
}
Here is one of my attempts to modify it:
{
"query": {
"nested": {
"path": "imageTags",
"score_mode": "sum",
"query": {
"function_score": {
"query": {
"match": {
"imageTags.tag.keyword": "tripod"
}
},
"field_value_factor": {
"field": "imageTags.score",
"factor": 1,
"missing": 0
}
}
}
}
}
}
By example, here is and example of the index:
{
"id": "4a9afd93-62bc-e8b2-29b4-39f5b073336d",
"tags": [
"fashion",
"mode",
"summer"
],
"imageTags": [
{
"score": 0.95150965,
"tag": "four-poster"
},
{
"score": 0.014835004,
"tag": "window"
},
{
"score": 0.014835004,
"tag": "shade"
},
{
"score": 0.009375425,
"tag": "sliding"
},
{
"score": 0.009375425,
"tag": "door"
}
],
"taxonomies": [],
"categories": [],
"qualityScore": 0.0,
"geoLocations": [
{
"lat": 50.4651156,
"lon": 4.865208
}
],
"storesIds": [
"ba9b3f59-50aa-8774-11a7-39f5ad58ae1a"
],
"storesNames": [
"Zara Namur"
],
"creationTime": "2020-06-10T12:48:30.5710000Z",
"updateTime": "2020-06-10T12:48:30.5710000Z",
"imageUri": "https://localhost:44359/cdn/e_76372856-f7a0-49cc-d3d9-39f5ad58ad6d/653d147084637b2af68b39f5b0733359.jpg",
"description": "",
"likesCount": 0,
"viewsCount": 0,
"commentsCount": 0,
"ImageTags": [
{
"score": 0.95150965,
"tag": "four-poster"
},
{
"score": 0.014835004,
"tag": "window"
},
{
"score": 0.014835004,
"tag": "shade"
},
{
"score": 0.009375425,
"tag": "sliding"
},
{
"score": 0.009375425,
"tag": "door"
}
]
}

malformed query, expected [END_OBJECT] but found [FIELD_NAME]

The original query looks like this
{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
713
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}
And I got some result
"hits": {
"total": 19,
"max_score": null,
"hits": [
{
"_index": "prices",
"_type": "doc",
"_id": "item-6800004",
"_score": null,
"_routing": "1",
"_source": {
"id": 6800004,
"id_pricedoc": 713,
"title": "\"водка №1\" 1",
"title_low": "\"водка №1\" 1",
"supplier": {
"id": 7831,
"type": null
},
"supplier_nom": {
"id": 1375697,
"market_nom": {
"id": null
},
"codes": null,
"sup_code": "7a6713a5-73c1-3acb-9b62-9e38b2314dce",
"manufacturer": {
"id": null,
"title": null
}
},
"is_folder": false,
"folder": null,
"path": null,
"pricedoc_created": "2016-03-21",
"prices": [
{
"currency": "RUR",
"id_offer": 15735967,
"id_prcknd": 167,
"value": "391.50"
}
],
"have_prices": true,
"market": {
"title": null,
"uuid": null,
"folder": null,
"path": null
},
"_join_field_name": "doc_type",
"doc_type": {
"name": "item",
"parent": "doc-713"
}
},
"sort": [
0,
"\"водка №1\" 1"
]
}
Now I also would like get result where "id_prcknd": 167
Modified query looks like this
{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
713
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
},
"nested": {
"path": "prices",
"query": {
"bool": {
"must": [
{
"match": {
"prices.id_prcknd": 167
}
}
]
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}}
But I got an error Elasticsearch malformed query, expected [END_OBJECT] but found [FIELD_NAME]
Where am I wrong?
I wanna match objects where "id_prcknd": 167
The stackoverflow says the I post mostly the code, but it's because of large queries in elastic search.
What Elasticsearch was trying to say is that it did not expect to see other keys but bool in the dictionary (the value under "query").
In your example code you have something like this:
{
"query": {
"bool": {
"must": [
{...},
{...},
{...}
],
"must_not": {...},
"nested": {...}, // this should go under "must"
"sort": [...], // this should go on the same level as "query"
"size": 1000 // this should go on the same level as "query"
}
}
"bool" here refers to a bool query, and should be the only key in the dictionary.
What you should do is to move "nested" into its own dictionary and the fourth element of the must array (if I understood the logic of what you are trying to achieve correctly). Please note that also "sort" and "size" should be moved - this time, to the same level as "query".
The full query will look like this:
{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
713
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
},
{
"nested": {
"path": "prices",
"query": {
"bool": {
"must": [
{
"match": {
"prices.id_prcknd": 167
}
}
]
}
}
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}
Your json is incorrect: Error:Expecting closing } at end[Code 22, Structure 183]
Use a json validator (https://jsonformatter.curiousconcept.com/) for example.

How can I stack search criteria using & in a nested query in ElasticSearch

I have this index mapping with nested fields:
"customerpropertieses": {
"_parent": {
"type": "customerprofile"
},
"_routing": {
"required": true
},
"properties": {
"id": {
"type": "string"
},
"parentId": {
"type": "string"
},
"properties": {
"type": "nested",
"properties": {
"extentionPropertyId": {
"type": "long"
},
"propertyName": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
I want to find customerpropertieses where propertyName=criteria1 & value=value1 & propertyName=criteria2 & value=value2
The query I'm generating by hand is this:
{
"from": 0,
"size": 10,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"nested": {
"query": {
"bool": {
"must": [
{
"match": {
"properties.propertyName": {
"query": "criteria1 "
}
}
},
{
"match": {
"properties.value": {
"boost": 10.0,
"query": "value1"
}
}
},
{
"match": {
"properties.propertyName": {
"query": "criteria2"
}
}
},
{
"match": {
"properties.value": {
"boost": 10.0,
"query": "value2"
}
}
}
]
}
},
"path": "properties",
"inner_hits": {
"explain": false
},
"_name": "nested_properties"
}
}
}
I get 0 results back and I certainly have data with those characteristics. The search works fine when I look only propertyName=criteria1 & value=value1 or with propertyName=criteria2 & value=value2'
The question is how can I stack search criteria using & in a nested query?
Try the following query. From the look of your query i take a guess you want to match documents which had two nested documents with values value1,criteria1 and value2,criteria2 in value and criteria field respectively.
{
"from": 0,
"size": 10,
"sort": [{
"_score": {
"order": "desc"
}
}],
"query": {
"bool": {
"must": [{
"nested": {
"query": {
"bool": {
"must": [{
"match": {
"properties.propertyName": {
"query": "criteria2"
}
}
}, {
"match": {
"properties.value": {
"boost": 10.0,
"query": "value2"
}
}
}]
}
},
"path": "properties",
"inner_hits": {
"explain": false
},
"_name": "nested_properties"
}
}, {
"nested": {
"query": {
"bool": {
"must": [{
"match": {
"properties.propertyName": {
"query": "criteria1 "
}
}
}, {
"match": {
"properties.value": {
"boost": 10.0,
"query": "value1"
}
}
}]
}
},
"path": "properties",
"inner_hits": {
"explain": false
},
"_name": "nested_properties"
}
}]
}
}
}
I indexed the following document making the guess and modified the query
The Following document will match the query above
{
"parentId" : "3434",
"properties" : [{
"extentionPropertyId" : 24,
"propertyName" : "criteria1",
"value" : "value1"
},{
"extentionPropertyId" : 24,
"propertyName" : "criteria2",
"value" : "value2"
}]
}
Hope this helps.
Thanks

What is wrong with my elasticsearch query ? Getting a expected end object error

I'm trying to do a elasticsearch query that does geolocation filter and does some matching on nested documents, but I'm getting this error whenever I add in the nested query.
"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]"
{
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "10km",
"geolocation": [
-73.980090948125,
40.747844918436
]
}
},
"must": {
"multi_match": {
"query": "New York",
"fields": [
"name^2",
"city",
"state",
"zip"
],
"type": "best_fields"
}
}
},
"nested": {
"path": "amenities",
"query": {
"bool": {
"must": [
{
"match": {
"amenities.name": "Pool"
}
}
]
}
}
}
},
"aggs": {
"reviews": {
"nested": {
"path": "reviews"
},
"aggs": {
"avg_rating": {
"avg": {
"field": "reviews.rating"
}
}
}
}
}
}
You just has misplaced the nested query, try like this:
{
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "10km",
"geolocation": [
-73.980090948125,
40.747844918436
]
}
},
"must": [
{
"multi_match": {
"query": "New York",
"fields": [
"name^2",
"city",
"state",
"zip"
],
"type": "best_fields"
}
},
{
"nested": {
"path": "amenities",
"query": {
"match": {
"amenities.name": "Pool"
}
}
}
}
]
}
},
"aggs": {
"reviews": {
"nested": {
"path": "reviews"
},
"aggs": {
"avg_rating": {
"avg": {
"field": "reviews.rating"
}
}
}
}
}
}

elasticsearch scoring muliple using nested function_scores

I'm trying to find the right approach for nested scoring functions.
DATA:
PUT test
PUT test/test/_mapping
{
"properties": {
"driver_id": {
"type": "integer"
},
"driver_name": {
"type": "string"
},
"cities": {
"type": "nested",
"properties": {
"city_id": {
"type": "integer"
},
"used": {
"type": "float"
}
}
},
"cars": {
"type": "nested",
"properties": {
"car_id": {
"type": "integer"
},
"used": {
"type": "float"
}
}
}
}
}
PUT test/test/1
{
"id":1,
"driver_name":"Lady Smith",
"cars":[{"car_id":1,"brand":"Ford Focus","used":0.5},{"car_id":2,"brand":"Toyota Corola","used":0.5}],
"city":[{"city_id":3,"name":"Tel Aviv","used":0.8},{"city_id":4,"name":"New York","used":0.2}]
}
PUT test/test/2
{
"id":2,
"driver_name":"John Smith",
"cars":[{"car_id":1,"brand":"Ford Focus","used":0.3},{"car_id":2,"brand":"Toyota Corola","used":0.3}],
"city":[{"city_id":3,"name":"Tel Aviv","used":0.8},{"city_id":4,"name":"New York","used":0.2}]
}
PUT test/test/3
{
"id":3,
"driver_name":"Will Smith",
"cars":[{"car_id":1,"brand":"Ford Focus","used":0.1}],
"city":[{"city_id":3,"name":"New York","used":0.2}]
}
PUT test/test/4
{
"id":4,
"driver_name":"Ash Smith",
"cars":[],
"city":[]
}
To put it simply, given the data, I would like to get the best fit to the query of the driver that drives a Ford AND a Corolla in Tel Aviv.
Or, translated loosly to SQL:
SELECT driver_id,
cr.cars_score * ct.city_score AS driver_score
FROM drivers drv
LEFT JOIN (SELECT sum(used) / 2 as cars_score
FROM car_usage
WHERE car_id IN (1,2) GROUP BY driver_id) AS cr
ON (cr.driver_id = drv.driver_id)
LEFT JOIN (SELECT sum(used) / 1 as city_score
FROM city_usage
WHERE city_id IN (3) GROUP BY driver_id) AS ct
ON (ct.driver_id = drv.driver_id)
Tried the following:
{
"query": {
"bool": {
"disable_coord": true,
"must": [
{
"query": {
"bool": {
"disable_coord": true,
"must": [{
"function_score": {
"query": {
"nested": {
"path": "cars",
"query": {
"function_score": {
"filter": {
"term": {
"cars.car_id": 1
}
},
"boost_mode": "replace",
"score_mode": "sum",
"functions": [
{
"field_value_factor": {
"field": "cars.used",
"factor":0.5,
"missing": 0
}
}
]
}
}
}
}
}
}, {
"function_score": {
"query": {
"nested": {
"path": "cars",
"query": {
"function_score": {
"filter": {
"term": {
"cars.car_id": 2
}
},
"boost_mode": "replace",
"score_mode": "sum",
"functions": [
{
"field_value_factor": {
"field": "cars.used",
"factor":0.5,
"missing": 0
}
}
]
}
}
}
}
}
}
]
}
}
},
{
"function_score": {
"query": {
"nested": {
"path": "cities",
"query": {
"function_score": {
"filter": {
"term": {
"cities.city_id": 3
}
},
"score_mode": "multiply",
"boost_mode": "replace",
"functions": [
{
"field_value_factor": {
"field": "cities.used",
"missing": 0
}
}
]
}
}
}
}
}
}
]
}
}
}
which gave me weird results.
then tried:
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "cars",
"query": {
"function_score": {
"filter": {
"term": {
"cars.car_id": 1
}
},
"score_mode": "sum",
"boost_mode":"replace",
"functions": [
{
"field_value_factor": {
"field": "cars.used",
"factor":0.5,
"missing": 0
}
}
]
}
}
}
},
{
"nested": {
"path": "cars",
"query": {
"function_score": {
"filter": {
"term": {
"cars.car_id": 2
}
},
"score_mode": "sum",
"boost_mode":"replace",
"functions": [
{
"field_value_factor": {
"field": "cars.used",
"factor":0.5,
"missing": 0
}
}
]
}
}
}
},
{
"nested": {
"path": "cities",
"query": {
"function_score": {
"filter": {
"term": {
"cities.city_id": 3
}
},
"score_mode":"multiply",
"boost_mode":"replace",
"functions": [
{
"field_value_factor": {
"field": "cities.used",
"missing": 0
}
}
]
}
}
}
}
]
}
}
}
which was closer, but seemed to just sum all scores.
A friend of mine suggested flatting the entire JSON, and losing the nested objects (making them properties) but I'm unsure as to whether that will make it easier to query the data.
UPDATE 1
another failed attempt :
{
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"nested": {
"path": "cars",
"query": {
"function_score": {
"filter": {
"term": {
"cars.car_id": 1
}
},
"score_mode": "sum",
"functions": [
{
"field_value_factor": {
"field": "cars.used",
"factor": 0.5,
"missing": 0
}
}
]
}
}
}
},
{
"nested": {
"path": "cars",
"query": {
"function_score": {
"filter": {
"term": {
"cars.car_id": 2
}
},
"score_mode": "sum",
"functions": [
{
"field_value_factor": {
"field": "cars.used",
"factor": 0.5,
"missing": 0
}
}
]
}
}
}
},
{
"nested": {
"path": "cities",
"query": {
"function_score": {
"filter": {
"term": {
"cities.city_id": 3
}
},
"score_mode": "multiply",
"functions": [
{
"field_value_factor": {
"field": "cities.used",
"missing": 0
}
}
]
}
}
}
}
]
}
},
"score_mode": "multiply"
}
}
}
UPDATE 2
Following my alternative method of flattening the fields and losing the nested filters, I ended with the following:
PUT test2
PUT test2/test2/1
{
"id":1,
"driver_name":"Lady Smith",
"cars_1":{"brand":"Ford Focus","used":0.5},
"cars_2":{"brand":"Toyota Corola","used":0.5},
"cities_3":{"name":"Tel Aviv","used":0.8},
"cities_4":{"name":"New York","used":0.2}
}
PUT test2/test2/2
{
"id":2,
"driver_name":"John Smith",
"cars_1":{"brand":"Ford Focus","used":0.3},
"cars_2":{"brand":"Toyota Corola","used":0.3},
"cities_3":{"name":"Tel Aviv","used":0.8},
"cities_4":{"name":"New York","used":0.2}
}
PUT test2/test2/3
{
"id":3,
"driver_name":"Will Smith",
"cars_1":{"brand":"Ford Focus","used":0.1},
"cities_4":{"name":"New York","used":0.2}
}
PUT test2/test2/4
{
"id":4,
"driver_name":"Ash Smith",
}
post test2/_search
{
"query": {
"bool": {
"disable_coord": true,
"must": [
{
"match": {
"name": "red pepper"
}
}
],
"should": [
{
"nested": {
"path": "words",
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field" : "words.weight",
"missing": 0
}
}
],
"query": {
"match": {
"words.text": "red pepper"
}
},
"score_mode": "sum",
"boost_mode": "replace"
}
},
"score_mode": "total"
}
}
]
}
}
}
GET test2/_search
{
"query": {
"function_score": {
"query":{
"bool":{
"must":[{
"exists":{"field":"cars_1"}
},{
"exists":{"field":"cars_2"}
},{
"exists":{"field":"cities_3"}
}]
}
},
"score_mode": "multiply",
"boost_mode": "replace",
"functions": [{
"script_score": {
"script": {
"inline": "(doc['cars_1.used'].value + doc['cars_2.used'].value) / 2 * doc['cities_3.used'].value"
}
}
}]
}
}
}
But I am not sure of the performance hit of the inline script. feels like I'm missing a simpler solution.
Just for future reference of people who visit this post,
I ended up changing my data model, and using script_score (lang:"painless" in 5.0.0)
Warning: this method, although did fit my need, had an impact on performance, eyeballing estimate would be a hit of around 3-5 fold slower response time.
For now, it's good enough for me.
PUT test2
PUT test2/test2/1
{
"id":1,
"driver_name":"Lady Smith",
"cars_1":{"brand":"Ford Focus","used":0.5},
"cars_2":{"brand":"Toyota Corola","used":0.5},
"cities_3":{"name":"Tel Aviv","used":0.8},
"cities_4":{"name":"New York","used":0.2}
}
PUT test2/test2/2
{
"id":2,
"driver_name":"John Smith",
"cars_1":{"brand":"Ford Focus","used":0.3},
"cars_2":{"brand":"Toyota Corola","used":0.3},
"cities_3":{"name":"Tel Aviv","used":0.8},
"cities_4":{"name":"New York","used":0.2}
}
PUT test2/test2/3
{
"id":3,
"driver_name":"Will Smith",
"cars_1":{"brand":"Ford Focus","used":0.1},
"cities_4":{"name":"New York","used":0.2}
}
PUT test2/test2/4
{
"id":4,
"driver_name":"Ash Smith",
}
post test2/_search
{
"query": {
"bool": {
"disable_coord": true,
"must": [
{
"match": {
"name": "red pepper"
}
}
],
"should": [
{
"nested": {
"path": "words",
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field" : "words.weight",
"missing": 0
}
}
],
"query": {
"match": {
"words.text": "red pepper"
}
},
"score_mode": "sum",
"boost_mode": "replace"
}
},
"score_mode": "total"
}
}
]
}
}
}
GET test2/_search
{
"query": {
"function_score": {
"query":{
"bool":{
"must":[{
"exists":{"field":"cars_1"}
},{
"exists":{"field":"cars_2"}
},{
"exists":{"field":"cities_3"}
}]
}
},
"score_mode": "multiply",
"boost_mode": "replace",
"functions": [{
"script_score": {
"script": {
"inline": "(doc['cars_1.used'].value + doc['cars_2.used'].value) / 2 * doc['cities_3.used'].value"
}
}
}]
}
}
}

Resources