简体   繁体   English

用于Elasticsearch中查询的Javascript API

[英]Javascript API for query in Elasticsearch

If I do below query in Kibana, results : " tim is a good boy " and I want to same thing using js library in eclipse. 如果我在Kibana中执行以下查询,则结果为:“ tim is a good boy ”,我想在Eclipse中使用js库进行相同操作。

GET nirv/_search
{
    "query" : {
        "term" : { "user" : "tim" }
    }
}

I looked everywhere but did not find much of help. 我到处看,但没有找到太多帮助。 So can anyone provide a bit of code for a query to Elasticsearch using JS API in eclipse. 任何人都可以使用Eclipse中的JS API向Elasticsearch查询提供一些代码。 What I mean is that I have a function result which provides me what elasticsearch return for particular query. 我的意思是,我有一个函数结果,该结果为我提供了针对特定查询的Elasticsearch返回值。

Are you using the javascript client library provided by Elasticsearch? 您是否正在使用Elasticsearch提供的javascript客户端库

Their docs show examples on how to get started and perform a search with the client: 他们的文档显示了有关如何开始和与客户进行搜索的示例:

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
  host: 'nirv'
});

client.search({
  user: 'tim'
}).then(function (body) {
  var hits = body.hits.hits; // "tim is a good boy" should be here *somewhere*
}, function (error) {
  console.trace(error.message);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM