I have an esri search widget I'm building like so:

const searchWidget = new Search({
    view: view,
    id: "search_widget",
    locationEnabled: true,
    includeDefaultSources: false,
    sources: [
            name: "CA Locator",
            placeholder: "Enter a CA address...",
            countryCode: "US",
            locator: new Locator({
                url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"
            singleLineFieldName: "SingleLine",
            outFields: ["State", "Addr_type"],
            suffix: ", California, USA",
            filter: {where: "State = 'California'"}

I've tried to add a suffix in attempts to force the searchTerm to resolve to California without luck.

How can I use filter with World GeocodeServer?

1 Answer 1


You could use ArcGIS Rest API: https://developers.arcgis.com/rest/services-reference/find-address-candidates.htm

Here you can define the serachExtent parameter to restrict the results to California's extent.

You can do the same using: https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-AddressCandidate.html#extent

However, since the extent does not contain the detail geometry boundary of the California state it could have results from adjacent states.

The other workaround is to add event: https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#event:select-result

From the event object of "select-result", you can apply spatial query using "esri/tasks/support/Query" to filter the points in California geometry.

Unfortunately, the Search module does not have any properties or methods to implement the requirement. You will need to add additional logic to filter the results respecting certain geometries.

  • Thanks, I will look into this. What I've done as a work around is add a suffix of ", California, USA" to the searchTerm which doesn't always result only in suggestions in CA but I filter them down manually. The more specific they get the better the suggestions. It's not great because it's not guaranteed to have suggestions as early as one would expect. Commented Apr 13, 2019 at 16:50
  • What is confusing me is why the filter doesn't work on the search. I would expect the where clause to reduce the suggestions to those in CA. Commented Apr 13, 2019 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.