appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.91k stars 468 forks source link

customQuery with script_fields script fields not included in query #949

Closed getorca closed 5 years ago

getorca commented 5 years ago

Issue Type: bug

Platform: ReactiveSearch for Web 2.18.0 ReactiveMaps 2.0.1

Description: Including script_fields in the customquery on a GeoDistanceDropdown the query DSL doesn't contain the script_fields. ie. script_fields is dropped form the DSL.

                                  customQuery={
                                    function(location, distance, props) {
                                        return {
                                        // query in the format of Elasticsearch Query DSL
                                            query: {
                                                geo_distance: {
                                                  "distance": distance + props.unit,
                                                  "location.lat_long": location
                                                }
                                            },
                                            script_fields: {
                                                geo_distance: {
                                                    script: {
                                                        params: {
                                                            lat: loc_arr[0],
                                                            lon: loc_arr[1]
                                                        },
                                                        source: "doc['location.lat_long'].arcDistance(params.lat, params.lon)"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                  }

The request body for the query has dropped the script_fields

siddharthlatest commented 5 years ago

Hey @getorca, which version of ReactiveSearch is this issue happening with?

getorca commented 5 years ago

@siddharthlatest reactivesearch 2.18.0 reactivemaps 2.0.1

It could also be related to a reactivemaps component, the custom query is on a GeoDistanceDropdown search filter.

siddharthlatest commented 5 years ago

Thanks! We've fixed this behavior in v3, currently on 3.0.0-rc.0 release.

getorca commented 5 years ago

Thanks! We've fixed this behavior in v3, currently on 3.0.0-rc.0 release.

@siddharthlatest I'm experiencing the same behaviour in 3.0.0-rc.3 as mentioned above

bietkul commented 5 years ago

I don't think we support this behavior in reactive-maps.

getorca commented 5 years ago

okay, might not be a bug, but an unexpected behaviour. Should probably update the docs and examples that mention "in the format of Elasticsearch Query DSL"

<GeoDistanceDropdown
  ...
  className="custom-class"
  style={{"paddingBottom": "10px"}}
  customQuery={
    function(location, distance, props) {
      return {
        // query in the format of Elasticsearch Query DSL
        geo_distance: {
          distance: distance + props.unit,
          location_dataField: location
        }
      }
    }
  }

https://opensource.appbase.io/reactive-manual/v3/map-components/geodistancedropdown.html