javascriptangularjselasticsearchgeojsonelasticsearch-geo-shape

integrating geojson query to generate http requests in angularjs


i am trying to integrate geoshape query from elastic search into my angularjs code to make an http request to fetch the data that is residing on elasticsearch local instance but the console throws error that invalid XMLhttp parameters. I guess it is related to how i am adding the geojson with my URL. Following is the function where i am creating the http request

function spatialsearch() {
            var _url = '127.0.0.1:9201/_search?';

            var b = {
                "query": {
                    "bool": {
                        "must": {
                            "match_all": {}
                        },
                        "filter": {
                            "geo_shape": {
                                "metadata.o2r.spatial.geometry": {
                                    "shape": {
                                        "type": "polygon",
                                        "coordinates": [
                                            [
                                                [-22.0, 76.0],
                                                [-27.0, 65.0],
                                                [-57.0, 65.0],
                                                [-59.0, 76.0],
                                                [-22.0, 76.0]
                                            ]
                                        ]
                                    },
                                    "relation": "contains"
                                }
                            }
                        }
                    }
                }
            };
            _url += b;
            return $http.get(_url);
            console.log("hello");

        }

Here is how i am calling http request in my js file in angularjs

function callingspatialsearch(){
  var deferred = $q.defer();
 httpRequests.
 spatialsearch()
 .then(cb1)
 .catch(errorHandler);
return deferred.promise;


    function cb1(response){
      $log.debug('result of search: %o', response);
      deferred.resolve(response);
    }

    function errorHandler(e){
      $log.debug('search error: %o', e);
      deferred.resolve(e);
    }
  }

In my HTML i am adding a button so that when user clicks on button the results are displayed.

<md-button ng-click="vm.button()" class="search-button md-primary md-raised white-font">Spatial</md-button>

Solution

  • i am using $http.post(_url) instead of GET and that helps me in retrieving results