【问题标题】:How to insert data into the index in ElasticSearch using Java如何使用 Java 将数据插入 ElasticSearch 中的索引
【发布时间】:2014-07-09 07:13:13
【问题描述】:

我是弹性搜索的新手。我已经使用 CURL 完成了插入、更新和搜索。我需要知道如何使用 java 来实现它。有什么方法吗?

谢谢

【问题讨论】:

标签: elasticsearch


【解决方案1】:

我会给你一个来自elasticsearch官方文档的例子:

import static org.elasticsearch.common.xcontent.XContentFactory.*;

IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
    .setSource(jsonBuilder()
                .startObject()
                    .field("user", "kimchy")
                    .field("postDate", new Date())
                    .field("message", "trying out Elasticsearch")
                .endObject()
              )
    .execute()
    .actionGet();

更多详情请查看官方Elasticsearch Java API page

【讨论】:

  • 谢谢。但是我怎么能在 Httpclient 的帮助下使用它。你能帮帮我吗?
  • 您可能会找到答案here
  • HttpClientConfig 无法解析为类型:我的代码是:Client Config client Config = new Client Config.Builder(System.getenv ("http://localhost:9200")) .multiThreaded(true )。建造();我该如何解决这个问题。请问如何解决此客户端配置生成器无法解析为类型。你能请任何人帮助我吗?
  • 你必须更新你的问题,解释你打算做什么没有在评论中回答
  • Java API页面超链接错误,单词索引后的下划线需要去掉,the correct link
猜你喜欢
  • 1970-01-01
  • 2015-03-29
  • 2011-12-30
  • 2014-05-17
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多