Request elasticSearch function_score with filters

Trying to create a search that returns results of a location that are about 500 m from a specific point in the geometry.

I need to filter the results of this search based on whether the place is empty in the source or not.

I tried things like this:

"filtered" : {
    "filter": {
        "missing" : { "field" : "location" }
    }
}

This is the JSON search I received:

 {"query": {
        "function_score": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "match": {"fieldA": "value"}
                        },
                        {
                            "match": { "fieldB": "value"}
                        }
                    ]
                }
            },
            "functions": [{
                    "gauss": {
                        "location": {
                            "origin": "'.$lat.','.$lon.'",
                            "scale": "500m",
                            "offset": "0km",
                            "decay": 0.33
                        }
                    }
                }]
        }
    }
}

I tried to put the filter in different places in the request, but it did not work for me, so I know that I am doing something fundamentally wrong with the way the request is structured. In the future I want to add more counting logic and other filters, but I cannot find a good example of such queries.

What should I do to make it work?

+4
source share
1 answer

geo_distance, . "" function_score "match":

{
   "query": {
      "function_score": {
         "query": {
            "filtered": {
               "query": {
                  "bool": {
                     "must": [
                        {
                           "match": {
                              "fieldA": "value"
                           }
                        },
                        {
                           "match": {
                              "fieldB": "value"
                           }
                        }
                     ]
                  }
               },
               "filter": {
                  "geo_distance" : {
                        "distance" : "500m",
                        "location" : "'.$lat.','.$lon.'"
                    }
               }
            }
         },
         "functions": [
            {
               "gauss": {
                  "location": {
                     "origin": "'.$lat.','.$lon.'",
                     "scale": "500m",
                     "offset": "0km",
                     "decay": 0.33
                  }
               },
               "weight": "3"
            }
         ]
      }
   }
}
+15

All Articles