zoukankan      html  css  js  c++  java
  • 通过Shell命令与JavaAPI读取ElasticSearch数据 (能力工场小马哥)

    主要内容: 通过JavaAPI和Shell命令两种方式操作ES集群

    集群环境: 两个

      1,未配置集群名称的单节点(模拟学习测试环境);

      2,两个节点的集群(模拟正常生产环境).

      JDK8+ElasticSearch5.1.2(大版本一致即可)

    Shell命令: 首先存入一条数据

    1 curl -X PUT localhost:9200/website/blog/1 -d '{
    2 "name":"51nenli"
    3 }'

    未配置集群名称的单节点(模拟学习测试环境)

    curl -Xget 'localhost:9200/website/blog/1' -- 或者使用如下带格式化的命令
    curl -Xget 'localhost:9200/website/blog/1?pretty'
    {
      "_index" : "website",
      "_type" : "blog",
      "_id" : "1",
      "_version" : 1,
      "found" : true,
      "_source" : {
        "name" : "51nenli"
      }
    }

    对应的JavaAPI代码如下

    1 TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
    2                     .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("xxx.xxx.xxx.xxx"), 9300));  //默认集群名称(elasticsearch)使用Settings.EMPTY默认配置就好了,xxx.xxx.xxx.xxx是你自己集群IP,注意端口是9300
    3 GetResponse response = client.prepareGet("website", "blog","1").setFetchSource(true).get(); //输入要查询的Index名称,Type名称,Id
    4 System.err.println(response.getSourceAsString());
    5 client.close();

    未完成

  • 相关阅读:
    装饰器模式
    doraemon的python 三元函数
    doraemon的python 文件操作
    doraemon的python 深浅拷贝和文件操作
    doraemon的python 集合
    doraemon的python 字典
    doraemon的python 列表
    doraemon 周总结1
    doraemon的python 练习
    doraemon的python之旅 整型、布尔值和字符串2
  • 原文地址:https://www.cnblogs.com/hadoop2015/p/9420828.html
Copyright © 2011-2022 走看看