Using filter and must together
"function_score": {
"score_mode": "avg",
"query": {
"bool": {
"filter": [
{
"exists": {
"field": "location"
}
},
{
"term": {
"blacklisted": false
}
},
{
"term": {
"has_matching_disabled": false
}
},
{
"term": {
"deleted": false
}
},
{
"range": {
"away_until": {
"lte": 1574766072
}
}
}
],
"must": [
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"geo_distance": {
"distance": "150km",
"location": {
"lat": 0.01,
"lon": 0.01
}
}
},
{
"nested": {
"path": "shooting",
"query": {
"bool": {
"filter": [
{
"exists": {
"field": "shooting.date"
}
},
{
"exists": {
"field": "shooting.location"
}
},
{
"range": {
"shooting.date": {
"gte": "2019-11-26T22:00:00+00:00",
"lte": "2019-11-27T00:00:00+00:00"
}
}
},
{
"geo_distance": {
"distance": "37.5km",
"shooting.location": {
"lat": 0.01,
"lon": 0.01
}
}
}
]
}
}
}
}
]
}
}
],
"must_not": [
{
"range": {
"unavailable": {
"gte": "2019-11-27T00:00:00+00:00",
"lte": "2019-11-27T00:06:00+00:00",
"format": "date_time_no_millis",
"relation": "intersects"
}
}
},
{
"range": {
"shooting.date": {
"gte": "2019-11-27T00:00:00+00:00",
"lte": "2019-11-27T00:06:00+00:00",
"format": "date_time_no_millis",
"relation": "intersects"
}
}
},
{
"term": {
"shooting.id": 37517382
}
}
]
}
},
"functions": [
{
"script_score": {
"script": {
"source": """<<<SOURCE HERE>>>""",
"params": {
"lat": 0.01,
"lon": 0.01,
"since": "2019-11-26T22:00:00+00:00",
"until": "2019-11-27T00:00:00+00:00",
"scale": 20,
"decay": 0.2
},
"lang": "painless"
}
},
"weight": 95
},
{
"field_value_factor": {
"field": "nb_shootings",
"modifier": "ln2p",
"missing": 0
},
"weight": 1
},
{
"field_value_factor": {
"field": "notation.meero",
"missing": 0.5
},
"weight": 1
},
{
"field_value_factor": {
"field": "notation.customer",
"missing": 0.5
},
"weight": 1
},
{
"random_score": [],
"weight": 2
}
]
}
Comments