ElasticSearch:华为云搜索CSS 之POC操作记录
2019/03/06 09:00
ES文档官方:https://support.huaweicloud.com/usermanual-es/es_01_0024.html
华为云区域:华北北京1
ES集群控制台:地址:
ECS控制台:地址:
ps:操作环境:华为云服务器上命令操作,使用bulk API通过cURL命令导入数据文件,以JSON数据文件为例。
华为云ES集群内网ip:xx.xx.xx.xx:9200
★查询索引
curl 'http://xx.xx.xx.xx:9200/_cat/indices'
查询索引下的数据
curl -XGET 'http://xx.xx.xx.xx:9200/poc_index/_search?pretty'
删除索引
curl -XDELETE 'http://xx.xx.xx.xx:9200/ddddd_index'
查询某一个索引库中的数据
查询整个索引库:curl -XGET http://master:9200/bigdata_p/_search?pretty
在url后面加上一个pretty则会对返回结果进行格式化,
查询某一个type:curl -XGET http://master:9200/bigdata_p/product/_search?pretty
查询具体的一条记录:curl -XGET http://master:9200/bigdata_p/product/1?pretty
查询一条索引文档中的具体的字段:curl -XGET http://master:9200/bigdata_p/product/1?_source=name&pretty
如果要查询多个字段,使用","进行隔开。eg.
curl -XGET http://master:9200/bigdata_p/product/1?_source=name,author&pretty
获取source所有数据
curl -XGET http://master:9200/bigdata_p/product/1?_source&pretty
根据条件进行查询
curl -XGET http://master:9200/bigdata_p/product/_search?q=name:hbase,hive&pretty
删除索引下的数据
POST /poc_index/_delete_by_query
{
"query": {
"match_all": {
}
}
}
★创建索引:
curl -X PUT http://xx.xx.xx.xx:9200/my_store -d '
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"products": {
"properties": {
"productName": {
"type": "text"
},
"size": {
"type": "keyword"
}
}
}
}
}' -H 'Content-Type: application/json'
ps: 添加 -H 'Content-Type: application/json' ,否则报错不支持json格式。
★本地创建test.json文件。添加内容:
{"index": {"_index":"my_store","_type":"products"}} {"productName": "2019秋装新款文艺衬衫女装","size": "M"}
-------------------------------------------------------------------------------------
ps:一定要记得在数据最后,添加换行,否则导入数据报错。!!!
需要注意的是{"index":{"_id":"1"}}和文件末尾另起一行换行是不可少的
参见文章:https://www.cnblogs.com/tonglin0325/p/8446975.html
★上传test.json文件到服务器,路径下执行命令导入数据。使用time命令打印命令的执行过程消耗的时间:
命令:
time curl -X PUT "http://xx.xx.xx.xx:9200/_bulk" -H 'Content-Type: application/json' --data-binary @test.json
以下为测试不同数量的数据导入结果:
1条:0.012s
1万条:3.013s
6万条:23.073s
=======================================================
使用springboot整合ES进行数据插入demo:
新建springboot项目:yml配置:
spring: #elasticsearch配置 data: elasticsearch: cluster-name: Es-23b6 cluster-nodes: 192.168.0.166:9300 repositories: enabled: true
ps:华为云ES控制台可以看到cluster-name和cluster-nodes,注意端口一定要改为9300,因为是集群的原因。否则异常:
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{S428skP0SrqzcOn8W7vhHg}{192.168.0.166}{192.168.0.166:9200}] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:349) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:247) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:381) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:407) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:396) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46) ~[elasticsearch-6.4.3.jar!/:6.4.3] at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.index(ElasticsearchTemplate.java:577) ~[spring-data-elasticsearch-3.1.5.RELEASE.jar!/:3.1.5.RELEASE] at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.save(AbstractElasticsearchRepository.java:156) ~[spring
参见文章:https://blog.csdn.net/adsl624153/article/details/78935796
pom中引入依赖:
<!-- elasticsearch --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch </artifactId> <version>2.0.2.RELEASE</version> </dependency>
先对ES创建索引:【linux命令行执行】
创建索引
curl -X PUT http://192.168.0.166:9200/my_store -d '
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"products": {
"properties": {
"id": {
"type": "long"
},
"productName": {
"type": "text"
},
"size": {
"type": "keyword"
}
}
}
}
}' -H 'Content-Type: application/json'
创建实体类:
package com.huawei.Bean; import org.springframework.data.elasticsearch.annotations.Document; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** * * @author :ayfei * @createTime :2019年3月5日下午2:13:31 * @description : */ @Data @AllArgsConstructor @NoArgsConstructor //indexName代表索引 名 称 ,type代表表名称 @Document(indexName = "my_store", type = "products") public class Notice { //id @JsonProperty("id") private Long id; // @JsonProperty("productName") private String productName; @JsonProperty("size") private String size; }
创建Dao层接口:
package com.huawei.Dao; /** * * @author :ayfei * @createTime :2019年3月5日下午2:15:26 * @description : */ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.stereotype.Component; import com.huawei.Bean.Notice; @Component public interface NoticeDao extends ElasticsearchRepository<Notice, Long> { }
controller层部分代码,直接调用ES的相关API:
@RequestMapping(value = "/saveOne", method = RequestMethod.POST) public String saveOne(@RequestBody @Valid Notice article){ long start = System.currentTimeMillis(); log.info("=====start System.currentTimeMillis()====="+start); noticeDao.save(article); long end = System.currentTimeMillis(); log.info("=====end System.currentTimeMillis()====="+end); long timeRes = end-start; log.info("存储一条数据到ES的执行时间"+ timeRes + "ms"); stringRedisTemplate.opsForValue().set("timeOneToES", timeRes+"ms"); return "存储一条数据到ES的执行时间"+ timeRes + "ms"; }
ElasticSearch:华为云搜索CSS 之POC操作记录的更多相关文章
- 华为云kafka POC 踩坑记录
2019/03/08 18:29 最近在进行华为云相关POC验证,个人主要负责华为云DMS kafka相关.大致数据流程是,从DIS取出数据,进行解析处理,然后放入kafka,再从kafka中取出数据 ...
- 大型情感剧集Selenium:6_selenium中的免密登陆与cookie操作 #华为云·寻找黑马程序员#
欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字"加群",加入华为云线上技术讨论群:输入关键字"最新活动",获取华 ...
- 华为云提供针对Nuget包管理器的缓存加速服务
在Visual Studio 2013.2015.2017中,使用的是Nuget包管理器对第三方组件进行管理升级的.而且 Nuget 是我们使用.NET Core的一项基础设施,.NET的软件包管理器 ...
- 云搜索服务在APP搜索场景的应用
搜索无处不在,尤其是在移动互联的今天.无论是社交,电商,还是视频等APP中,搜索都已经在其中扮演了重要的角色.作为信息的入口,搜索能帮用户从海量信息中找到想要的信息.在APP搜索的典型场景如下: ● ...
- CentOS 7.4 下搭建 Elasticsearch 6.3 搜索群集
上个月 13 号,Elasticsearch 6.3 如约而至,该版本和以往版本相比,新增了很多新功能,其中最令人瞩目的莫过于集成了 X-Pack 模块.而在最新的 X-Pack 中 Elastics ...
- 这个七夕节,用Python为女友绘制一张爱心照片墙吧!【华为云技术分享】
欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字“加群”,加入华为云线上技术讨论群:输入关键字“最新活动”,获取华为云最新特惠促销.华为云诸多技术大咖.特 ...
- 华为云·寻找黑马程序员#海量数据的分页怎么破?【华为云技术分享】
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...
- 使用Python开发小说下载器,不再为下载小说而发愁 #华为云·寻找黑马程序员#
需求分析 免费的小说网比较多,我看的比较多的是笔趣阁.这个网站基本收费的章节刚更新,它就能同步更新,简直不要太叼.既然要批量下载小说,肯定要分析这个网站了- 在搜索栏输入地址后,发送post请求获取数 ...
- 爬虫新宠requests_html 带你甄别2019虚假大学 #华为云·寻找黑马程序员#
python模块学习建议 学习python模块,给大家个我自己不专业的建议: 养成习惯,遇到一个模块,先去github上看看开发者们关于它的说明,而不是直接百度看别人写了什么东西.也许后者可以让你很快 ...
随机推荐
- python的语法糖
# -*- coding: utf-8 -*-def deco(func): print("before myfunc() called.") func() print(" ...
- shell if的使用
1 字符串判断 str1 = str2 当两个串有相同内容.长度时为真 str1 != str2 当串str1和str2不等时为真 -n str1 当串的长度大于0时为真(串非空) -z str1 当 ...
- p2921 Trick or Treat on the Farm
传送门 题目 每年万圣节,威斯康星的奶牛们都要打扮一番,出门在农场的N个牛棚里转 悠,来采集糖果.她们每走到一个未曾经过的牛棚,就会采集这个棚里的1颗糖果.农场不大,所以约翰要想尽法子让奶牛们得到快乐 ...
- storm shell命令源码分析-shell_submission.clj
当我们在shell里执行storm shell命令时会调用shell_submission.clj里的main函数.shell_submission.clj如下: shell_submission.c ...
- URAL 2021 Scarily interesting! (贪心+题意)
题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长. 析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次. ...
- 【转】Subversion快速入门教程-动画演示
如何快速建立Subversion服务器,并且在项目中使用起来,这是大家最关心的问题,与CVS相比,Subversion有更多的选择,也更加的容易,几个命令就可以建立一套服务器环境,可以使用起来,这里配 ...
- 【转-mysql-explain介绍】
explain显示了MySQL如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 先解析一条sql语句,看出现什么内容 EXPLAINSELECTs.uid, ...
- jquery ajax 与 update panel
回调函数
- 通过Python调用Spice-gtk
序言 通过Virt Manager研究学习Spice gtk的Python方法 你将学到什么 Virt Manager研究 显示代码定位 首先我们使用Virt Manager来观察桌面连接窗口 然后我 ...
- SQL Server 2012安装——.net framework 3.5离线安装
前言 电脑用着一直很不舒服,所以就决定对电脑重新配置一番,在装数据库这里,可谓是屡装屡败.自己感觉太麻烦了,于是每次数据库装失败后,就重装系统,然后配置上网文档,这样一来,弄得自己挺恶心,这次很明显成 ...