本文介绍了如何使用SEARCH_TYPE从elasticsearch JavaScript库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行计数 SEARCH_TYPE 搜索查询与elasticsearch.angular.js打造而成。

我可以执行这样的查询:

 {
   "aggs": {
   "reviews": {
     "nested": {
       "path": "reviews"
      }
    }
  }
}

but when I try to translate the query to the .js api, I get an error. My code looks like this:

  var requestObject = {
      index:'index1',
      type:'type1',
      searchType: 'count',
      body: {
        query:{
          aggs: {
            reviews: {
              nested: {
                path: "reviews"
              }
            }
          }
        }
    };
    esClient.search(requestObject)

The trace looks like this:

  console.js:1 DEBUG: 2015-08-04T15:28:59Z
      starting request { method: 'POST',
        path: '/index1/type1/_search',
        body: { aggs: { reviews: [Object] } },
        query: { search_type: 'count' } }

That looks OK to an elasticsearch newbie, but the request completes with an error: ReferenceError: count is not defined.

What am I missing here please?

解决方案

It turned out that my problem was a stupid error on my part (thanks @robertklep for pointing it out). The code above actually works correctly. As I was not able to find an example of using using searchType from the api, I am leaving this here in the hope it will be useful to somebody else.

这篇关于如何使用SEARCH_TYPE从elasticsearch JavaScript库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 16:56