Advertisement
brandizzi

Using filter and must together

Nov 27th, 2019
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 4.56 KB | None | 0 0
  1.     "function_score": {
  2.       "score_mode": "avg",
  3.       "query": {
  4.         "bool": {
  5.           "filter": [
  6.             {
  7.               "exists": {
  8.                 "field": "location"
  9.               }
  10.             },
  11.             {
  12.               "term": {
  13.                 "blacklisted": false
  14.               }
  15.             },
  16.             {
  17.               "term": {
  18.                 "has_matching_disabled": false
  19.               }
  20.             },
  21.             {
  22.               "term": {
  23.                 "deleted": false
  24.               }
  25.             },
  26.             {
  27.               "range": {
  28.                 "away_until": {
  29.                   "lte": 1574766072
  30.                 }
  31.               }
  32.             }
  33.           ],
  34.           "must": [
  35.             {
  36.               "bool": {
  37.                 "minimum_should_match": 1,
  38.                 "should": [
  39.                   {
  40.                     "geo_distance": {
  41.                       "distance": "150km",
  42.                       "location": {
  43.                         "lat": 0.01,
  44.                         "lon": 0.01
  45.                       }
  46.                     }
  47.                   },
  48.                   {
  49.                     "nested": {
  50.                       "path": "shooting",
  51.                       "query": {
  52.                         "bool": {
  53.                           "filter": [
  54.                             {
  55.                               "exists": {
  56.                                 "field": "shooting.date"
  57.                               }
  58.                             },
  59.                             {
  60.                               "exists": {
  61.                                 "field": "shooting.location"
  62.                               }
  63.                             },
  64.                             {
  65.                               "range": {
  66.                                 "shooting.date": {
  67.                                   "gte": "2019-11-26T22:00:00+00:00",
  68.                                   "lte": "2019-11-27T00:00:00+00:00"
  69.                                 }
  70.                               }
  71.                             },
  72.                             {
  73.                               "geo_distance": {
  74.                                 "distance": "37.5km",
  75.                                 "shooting.location": {
  76.                                   "lat": 0.01,
  77.                                   "lon": 0.01
  78.                                 }
  79.                               }
  80.                             }
  81.                           ]
  82.                         }
  83.                       }
  84.                     }
  85.                   }
  86.                 ]
  87.               }
  88.             }
  89.           ],
  90.           "must_not": [
  91.             {
  92.               "range": {
  93.                 "unavailable": {
  94.                   "gte": "2019-11-27T00:00:00+00:00",
  95.                   "lte": "2019-11-27T00:06:00+00:00",
  96.                   "format": "date_time_no_millis",
  97.                   "relation": "intersects"
  98.                 }
  99.               }
  100.             },
  101.             {
  102.               "range": {
  103.                 "shooting.date": {
  104.                   "gte": "2019-11-27T00:00:00+00:00",
  105.                   "lte": "2019-11-27T00:06:00+00:00",
  106.                   "format": "date_time_no_millis",
  107.                   "relation": "intersects"
  108.                 }
  109.               }
  110.             },
  111.             {
  112.               "term": {
  113.                 "shooting.id": 37517382
  114.               }
  115.             }
  116.           ]
  117.         }
  118.       },
  119.       "functions": [
  120.         {
  121.           "script_score": {
  122.             "script": {
  123.               "source": """<<<SOURCE HERE>>>""",
  124.               "params": {
  125.                 "lat": 0.01,
  126.                 "lon": 0.01,
  127.                 "since": "2019-11-26T22:00:00+00:00",
  128.                 "until": "2019-11-27T00:00:00+00:00",
  129.                 "scale": 20,
  130.                 "decay": 0.2
  131.               },
  132.               "lang": "painless"
  133.             }
  134.           },
  135.           "weight": 95
  136.         },
  137.         {
  138.           "field_value_factor": {
  139.             "field": "nb_shootings",
  140.             "modifier": "ln2p",
  141.             "missing": 0
  142.           },
  143.           "weight": 1
  144.         },
  145.         {
  146.           "field_value_factor": {
  147.             "field": "notation.meero",
  148.             "missing": 0.5
  149.           },
  150.           "weight": 1
  151.         },
  152.         {
  153.           "field_value_factor": {
  154.             "field": "notation.customer",
  155.             "missing": 0.5
  156.           },
  157.           "weight": 1
  158.         },
  159.         {
  160.           "random_score": [],
  161.           "weight": 2
  162.         }
  163.       ]
  164.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement