Angular Material Datepicker未使用Elasticsearch Range Query返回正确的结果

时间:2017-05-09 10:49:14

标签: angularjs elasticsearch

我正在尝试根据我正在创建的时间范围查询来获取已在本地ES服务器上编制索引的文档实例。我的文档是从01-03-201731-03-2017创建的。

HTTP请求:

temporalsearch: temporalsearch
function temporalsearch(beginfrom, beginto) {
            console.log("hello");
            var _url = 'http://127.0.0.1:9201/_search?';
            var b = {
                "query": {
                    "range" : {
                        "metadata.o2r.temporal.begin" : {
                            "gte": beginfrom,
                            "lte": beginto
                        }
                    }
                }
            };

            return $http.post(_url,b);
        }

使用Javascript:

function SearchController($scope,$stateParams, $q, $log, httpRequests, $location, searchResults, header, icons, leafletData) {
      var beginfrom;
      var beginto;

      var vm = this;
      $scope.beginfromDate = new Date();
      $scope.begintoDate = new Date();

      vm.beginfromDate = beginfromDate;
      vm.begintoDate = begintoDate;  

 function beginfromDate() {
     beginfrom = $scope.beginfromDate;
     console.log(JSON.stringify(beginfrom, 'bf'));
}

function begintoDate() {
    beginto = $scope.begintoDate;
    console.log(JSON.stringify(beginto,'bt'));
}

Javascript中的HTTP调用:

function callingtemporalsearch() {
    console.log('calling temporal search');
    var deferred = $q.defer();
    httpRequests.temporalsearch(beginfrom, beginto)
                .then(cb1)
                .catch(errorHandler);

    return deferred.promise;

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

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

HTML:

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

    <md-datepicker ng-model='beginfromDate'ng-change="vm.beginfromDate()"></md-datepicker>
                <h4>Begin To</h4>
                  <md-datepicker ng-model='begintoDate'ng-change="vm.begintoDate()" ></md-datepicker>

我希望能够在更改错误结果时停止更改指令搜索默认值的文档。

0 个答案:

没有答案