`
m635674608
  • 浏览: 5043485 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

elasticsearch jest client 注意事项

 
阅读更多
 public void indexSampleArticles() {

        Article article1 = new Article();
        article1.setId(10L);
        article1.setAuthor("Robert Anthony Salvatore2222222222222");
        article1.setContent("Homeland follows the story of Drizzt from around the time and circumstances of his birth and his upbringing amongst the drow (dark elves). " +
                "The book takes the reader into Menzoberranzan, the drow home city. From here, the reader follows Drizzt on his quest to follow his principles in a land where such " +
                "feelings are threatened by all his family including his mother Matron Malice. In an essence, the book introduces Drizzt Do'Urden," +
                " one of Salvatore's more famous characters from the Icewind Dale Trilogy.");

        Article article2 = new Article();
        article2.setId(3L);
        article2.setAuthor("John Ronald Reuel Tolkien");
        article2.setContent("The Lord of the Rings is an epic high fantasy novel written by English philologist and University of Oxford professor J. R. R. Tolkien. " +
                "The story began as a sequel to Tolkien's 1937 children's fantasy novel The Hobbit, but eventually developed into a much larger work. " +
                "It was written in stages between 1937 and 1949, much of it during World War II.[1] It is the third best-selling novel ever written, with over 150 million copies sold");

        try {
            // Delete articles index if it is exists
            //DeleteIndex deleteIndex = new DeleteIndex.Builder("articles").build();
            //jestClient.execute(deleteIndex);

            IndicesExists indicesExists = new IndicesExists.Builder("articles").build();
            JestResult result = jestClient.execute(indicesExists);

            if (!result.isSucceeded()) {
                // Create articles index
                CreateIndex createIndex = new CreateIndex.Builder("articles").build();
                jestClient.execute(createIndex);
            }

            /**
             *  if you don't want to use bulk api use below code in a loop.
             *
             *  Index index = new Index.Builder(source).index("articles").type("article").build();
             *  jestClient.execute(index);
             *
             */

            Bulk bulk = new Bulk.Builder()
                    .addAction(new Index.Builder(article1).index("articles").type("article").build())
                    .addAction(new Index.Builder(article2).index("articles").type("article").build())
                    .build();

            result = jestClient.execute(bulk);

            System.out.println(result.getJsonString());

        } catch (IOException e) {
            logger.error("Indexing error", e);
        } catch (Exception e) {
            logger.error("Indexing error", e);
        }

    }

   当重复id插入时,会做更新操作。

分享到:
评论

相关推荐

    Elasticsearch-JestClient

    **Elasticsearch-JestClient详解** Elasticsearch(简称ES)是一种流行的开源全文搜索引擎,它提供了高可扩展性、实时的搜索与分析能力。而JestClient是Java开发者用来与Elasticsearch通信的一个轻量级HTTP客户端库...

    jest-client.7z

    在提供的"jest-client"压缩包中,可能包含了一些示例代码或库,展示了如何使用Jest与Elasticsearch 6.8版本进行交互。这可以帮助开发者快速理解和集成这个客户端,实现日常开发中的各种操作。通过学习这些示例,你...

    Elasticsearch之Java客户端Jest的全部依赖jar包

    3. 执行操作:使用JestClient提供的接口执行各种Elasticsearch操作,如索引文档、搜索、更新、删除等。 4. 关闭资源:在完成操作后,记得关闭JestClient以释放资源。 Jest的优势在于其灵活性和性能。它可以很好地...

    ES5.5.1 JestClient示例

    Elasticsearch5.5.1使用JAVA客户端Jest操作的一些示例代码,详细介绍请参考文章:http://blog.csdn.net/u011781521/article/details/77852861

    elasticsearch-rest-client-6.8.3-API文档-中文版.zip

    赠送jar包:elasticsearch-rest-client-6.8.3.jar; 赠送原API文档:elasticsearch-rest-client-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-rest-client-6.8.3-sources.jar; 赠送Maven依赖信息文件:elastic...

    elasticsearch-rest-high-level-client-6.8.3-API文档-中文版.zip

    赠送jar包:elasticsearch-rest-high-level-client-6.8.3.jar; 赠送原API文档:elasticsearch-rest-high-level-client-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-rest-high-level-client-6.8.3-sources.jar;...

    elasticsearch-rest-client-6.2.3-API文档-中文版.zip

    赠送jar包:elasticsearch-rest-client-6.2.3.jar; 赠送原API文档:elasticsearch-rest-client-6.2.3-javadoc.jar; 赠送源代码:elasticsearch-rest-client-6.2.3-sources.jar; 赠送Maven依赖信息文件:elastic...

    elasticsearch-rest-client-6.3.0-API文档-中英对照版.zip

    赠送jar包:elasticsearch-rest-client-6.3.0.jar; 赠送原API文档:elasticsearch-rest-client-6.3.0-javadoc.jar; 赠送源代码:elasticsearch-rest-client-6.3.0-sources.jar; 赠送Maven依赖信息文件:elastic...

    用jest客户端将数据从hive导入elasticsearch

    然后,你可以创建一个JestClient实例来连接Elasticsearch集群,并执行索引、搜索等操作。 2. **Java通过JDBC连接Hive** 要从Hive获取数据,我们可以使用Hive JDBC驱动。首先,确保你的项目中包含Hive JDBC驱动的...

    elasticsearch-jest-example-master.zip

    3. **创建连接**:初始化JestClient实例,建立与Elasticsearch集群的连接。 4. **执行操作**:利用JestClient提供的API进行索引创建、文档插入、查询、更新和删除等操作。 5. **关闭客户端**:完成操作后,记得关闭...

    基于elasticsearch java client封装的elasticsearch.zip

    《基于Elasticsearch Java Client的封装实践》 在大数据时代,Elasticsearch作为一个高效、可扩展的全文搜索引擎,被广泛应用于日志分析、监控、数据可视化等领域。Java作为企业级应用开发的主流语言,Elastic...

    elasticsearch java客户端Jest入门实例

    通过Jest和Junit单元测试的方法创建索引和检索 第一步:启动一个elasticsearch服务,bin目录下的elasticsearch.bat 第二步:建索引,执行MusicReviewIndex中的单元测试...本实例基于: Jest 0.0.3,elasticsearch 0.20.5

    elasticsearch-rest-high-level-client-6.8.3-API文档-中英对照版.zip

    赠送jar包:elasticsearch-rest-high-level-client-6.8.3.jar; 赠送原API文档:elasticsearch-rest-high-level-client-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-rest-high-level-client-6.8.3-sources.jar;...

    elasticsearch RESTful搜索引擎-(java jest 使用[入门])

    Elasticsearch(简称ES)是一种分布式、全文检索的搜索引擎,广泛应用于日志分析、实时数据分析和搜索应用等场景。其核心特性包括强大的全文搜索能力、水平扩展性以及实时性。在Java环境中,Jest库提供了一个简洁...

    elasticsearch client api 离线文档

    API 包括 `RestHighLevelClient` 和 `TransportClient`,前者通过 RESTful 协议与 Elasticsearch 通信,后者则依赖于 Elasticsearch 的节点间通信协议(Transport Protocol)。 **Ruby 客户端 API** Elasticsearch ...

    elasticsearch-rest-client-6.3.0-API文档-中文版.zip

    赠送jar包:elasticsearch-rest-client-6.3.0.jar; 赠送原API文档:elasticsearch-rest-client-6.3.0-javadoc.jar; 赠送源代码:elasticsearch-rest-client-6.3.0-sources.jar; 赠送Maven依赖信息文件:elastic...

    elasticsearch-rest-client-6.8.3-API文档-中英对照版.zip

    赠送jar包:elasticsearch-rest-client-6.8.3.jar; 赠送原API文档:elasticsearch-rest-client-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-rest-client-6.8.3-sources.jar; 赠送Maven依赖信息文件:elastic...

    elasticsearch-rest-client-6.2.3-API文档-中英对照版.zip

    赠送jar包:elasticsearch-rest-client-6.2.3.jar; 赠送原API文档:elasticsearch-rest-client-6.2.3-javadoc.jar; 赠送源代码:elasticsearch-rest-client-6.2.3-sources.jar; 赠送Maven依赖信息文件:elastic...

    elasticsearch Client端的JAVA代码例子

    Elasticsearch (ES) 是一个分布式、RESTful风格的搜索和数据分析引擎,广泛用于实时数据检索、分析和存储。在Java开发中,我们通常使用官方提供的Java REST Client来与ES集群进行交互。 Java REST Client是Elastic...

    node-elasticsearch-client, 在 node的弹性搜索中,客户端编写了.zip

    node-elasticsearch-client, 在 node的弹性搜索中,客户端编写了 不再维护使用 https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html 弹性搜索客户端elasticsearch

Global site tag (gtag.js) - Google Analytics