brandizzi icon

Using filter and must together

brandizzi | PRO | 11/27/19 02:10:34 PM UTC | 0 ⭐ | 798 👁️ | Never ⏰ | []
JSON |

4.56 KB

|

None

|

0 👍

/

0 👎

    "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