如何使用SEARCH_TYPE从elasticsearch JavaScript库 [英] How to use search_type from elasticsearch javascript library

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

问题描述

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

我可以执行这样的查询:


  

POST /索引1/1型/ _search?SEARCH_TYPE =计数


  {
   AGGS:{
   评论:{
     嵌套:{
       路径:审查
      }
    }
  }
}

但是当我尝试将查询转换为.js文件API,我得到一个错误。我的code是这样的:

  VAR requestObject = {
      索引:指数1,
      类型:TYPE1,
      检索类别:'算',
      身体: {
        查询:{
          AGGS:{
            评论:{
              嵌套:{
                路径:评审
              }
            }
          }
        }
    };
    esClient.search(requestObject)

跟踪看起来是这样的:

  console.js:1 DEBUG:2015-08-04T15:28:59Z
      起始请求{方法:POST,
        路径:'/索引1/1型/ _search',
        正文:{AGGS:{评论:[对象]}},
        查询:{SEARCH_TYPE:计数}}

这看起来不错到elasticsearch新手,但请求出错完成:的ReferenceError:计数没有定义

我是什么在这里失踪吗?


解决方案

原来,我的问题是在我的部分(指点出来感谢@robertklep)一个愚蠢的错误。在code以上实际工作正常。因为我无法找到使用使用的例子检索类别从API,我在这里离开这个希望这将是给别人用。

I am trying to execute a search query with search_type of count with the elasticsearch.angular.js build from the npm module.

I can execute the query like this:

POST /index1/type1/_search?search_type=count

 {
   "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库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆