ElasticSearch 记录
来源:互联网 发布:怎么在pdf上签名 mac 编辑:程序博客网 时间:2024/05/17 15:58
version: 5.4.1
step 1 下载 elasticsearch
step 2 启动 {es_dir}/bin/.elasticsearch
创建索引、put一条数据
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{ "user":"lili", "post_date":"2017-06-09", "message":"Hello, ElasticSearch!"}'
Rest API 查询
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty'{ "took" : 0, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_score" : 1.0, "_source" : { "user" : "lili", "post_date" : "2017-06-09", "message" : "Hello, ElasticSearch!" } } ] }}
Java API 查询
1、POM.xml
<dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>5.4.1</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>5.4.1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency>
appender.console.type = Consoleappender.console.name = consoleappender.console.layout.type = PatternLayoutrootLogger.level = inforootLogger.appenderRef.console.ref = console
3、测试(jdk版本>=1.8)
public class ESDemo { public static void main(String[] args) throws Exception { Settings settings = Settings.builder() .put("cluster.name", "myes")//集群名称可以在{es_dir}/conf/elasticsearch.yml中配置 .put("client.transport.sniff", "true").build(); TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300)); QueryBuilder qb = termQuery("user", "lili"); SearchResponse response = client.prepareSearch("twitter") .setTypes("tweet").setQuery(qb).get(); if (response.getHits().getTotalHits() != 0) { SearchHits shs = response.getHits(); for (SearchHit sh : shs.getHits()) { System.out.println((sh.getSource().get("message"))); } } }}
阅读全文
0 0
- ElasticSearch 记录
- ElasticSearch安装记录
- elasticsearch使用记录
- ElasticSearch删除记录
- elasticsearch-hadoop使用记录
- elasticsearch学习记录
- elasticsearch安装记录
- Elasticsearch 时区(time_zone)记录
- elasticsearch 运维记录
- elasticsearch基础知识记录
- Elasticsearch安装学习记录
- elasticsearch Document相关操作记录
- 记录一次elasticsearch连接问题
- ElasticSearch安装问题的记录
- 关于elasticsearch的问题解决记录
- ElasticSearch学习笔记-同义词记录
- Elasticsearch JAVA API开发记录
- elasticsearch的基本使用记录
- [HDU-5976] [Problem F](逆元+二分优化+数学分析)
- ES6的数据结构set 和 map
- [Leetcode] 199. Binary Tree Right Side View 解题报告
- git生成ssh key 避免每次push都要输入账号密码
- 基点算法
- ElasticSearch 记录
- dubbo+zookeeper+SpringMVC详解
- python3安装xadmin出现 UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 3444
- ECharts柱状图实例
- hibernate学习之五——使用myeclipse部署及hibernate一些常见配置
- Java IO4 实现凯撒密码加密解密文本文件
- 第2章复杂HTML解析
- 一个可双击放大,双指放大的ImageView
- 怎么样做好网站关键词的选择与部署?