zoukankan      html  css  js  c++  java
  • 利用Node.js调用Elasticsearch

    1. 下载elasticsearch库

    npm install elasticsearch --save
    

    2.在脚本里导入模块,如下所示

    const elasticsearch = require('elasticsearch');
    

    3.调用

    function getReport(md5, callback) {
        var search =
        {
            index: 'file-behavior-report-*',
            type: 'report',
            body: {
                query: {
                    "bool": {"must": [{"match": {"md5": md5.toUpperCase()}}], "must_not": [], "should": []}
                },
                "from": 0,
                "size": 1,
                "sort": [],
                "aggs": {}
            }
        };
        getES(search, function (data) {
            callback(data);
        });
    }
    
    function getES(searchInfo, callback) {
        const esClient = new elasticsearch.Client({
            host: 'http://193.168.15.210:9200/',
            log: 'error'
        });
        esClient.search(searchInfo).then(function (re) {
            callback(re.hits.hits);
        }, function (err) {
            console.trace(err.message);
        });
    }
    

      

  • 相关阅读:
    java线程(1)-线程同步
    Scala:(3)数组
    Codeforces 899F Letters Removing
    拼图游戏的可解性
    Hash
    哈夫曼编码
    莫比乌斯
    FFT
    Ropes
    区间合并
  • 原文地址:https://www.cnblogs.com/guozhe/p/6427490.html
Copyright © 2011-2022 走看看