Elasticsearch基本操作
ElasticSearch操作说明
活动 |
方法 |
url |
Body |
集群的相关操作 |
|||
查看健康 |
Get |
||
查看节点 |
Get |
||
关闭节点 |
Post |
http://localhost:9200/_cluster/nodes/节点名字/_shutdown |
注意:每次启动后,节点名字都会改变 |
关闭集群 |
post |
||
索引的相关操作 |
|||
创建索引settings |
Post |
{} |
|
创建索引settings |
Post |
{ "settings": { "index": { "number_of_shards": "5", "number_of_replicas": "0" } }} |
|
修改一个索引setting |
Put 不能post |
{ "settings": { "index": { "number_of_replicas": "0" } }} |
|
删除索引setting |
Del |
||
删除所有索引setting |
Del |
http://localhost:9200/*/ |
|
查看具体索引setting |
Get |
||
关闭索引 |
Post |
http://localhost:9200/testindex/_close |
|
打开索引 |
post |
http://localhost:9200/testindex/_open |
|
查看所有索引setting |
Get |
||
添加一个type |
|||
添加/修改一个mapping |
Put/ post |
http://localhost:9200/testindex/testtype/_mapping |
{ "testtype" : { "properties" : { "address" : { "type" : "string" }, "name" : { "type" : "string" } } }} |
删除mapping |
del |
http://localhost:9200/testindex/testtype |
添加具体的文档
插入文档自动生成id |
Post |
http://localhost:9200/testindex/testtype/ post每次都是创建新的 |
{ "name":"张明", "address":"中山北路" } |
插入文档,更新或生成 |
put |
http://localhost:9200/testindex/testtype/1 put时带具体的ID,表示修改,没有则创建 |
{ "name":"张明", "address":"中山北路" } |
普通查询 |
Get |
{ "name":"张明", "address":"中山北路" } |
|
Query查询 |
Get |
{ "name":"张明", "address":"中山北路" } |
其他操作:
插入文档自动生成index/type |
Post |
http://localhost:9200/testindex/testtype/ post每次都是创建新的 |
{ "name":"张明", "address":"中山北路" } |
插入文档自动生成index/type |
put |
http://localhost:9200/testindex/testtype/1 put时带具体的ID,表示修改,没有则创建 |
{ "name":"张明", "address":"中山北路" } |
同时创建index、type,不插入文档 |
Post/ put |
http://localhost:9200/testindex
后面的json格式最好不要变动,一般情况下,只要post过去的内容和查询看到的格式保持一个层次结构,都可以提交; 但是提交的格式却不一定和查询看到的一致(毕竟提交只是需要将所有的信息加上去就可以了) |
{ "settings" : { "number_of_shards" : "5", "number_of_replicas" : "1" } , "mappings" : { "testtype" : { "properties" : { "address" : { "type" : "string" }, "age" : { "type" : "string" } } } } } |
刷新索引 |
Post |
http://localhost:9200/testindex/_refresh |
|
提交索引 |
Post |
http://localhost:9200/testindex/_flush |
|
优化索引 |
Post |
http://localhost:9200/testindex/_optimize |
|
清空缓存 |
Post |
http://localhost:9200/testindex/_cache/clear |
查询操作:
Math_all 全集查询 |
Post |
http://172.16.20.49:9200/zuhe/zuheentity/_search http://172.16.20.49:9200/*/zuheentity/_search |
{ } |
Math 语义查询 |
Post |
http://172.16.20.49:9200/zuhe/zuheentity/_search http://172.16.20.49:9200/*/zuheentity/_search |
{ "query":{ "match":{ "ManagerName":"财富" } } } |
Math_phrase 短语查询,term查询后,进行位置匹配,得到类似like结果 |
Post |
http://172.16.20.49:9200/zuhe/zuheentity/_search http://172.16.20.49:9200/*/zuheentity/_search |
{ "query":{ "match":{ "ManagerName":"财富" } } } |
Term 直接用倒排索引的词项进行查询,性能好,但在应用层面,直接使用的少 |
Post |
{ "query":{ "term":{ "ManagerName":{ "value":"财", "boost":10 } } } } |
|
Wildcard 在term查询的基础上,增加通配符功能 |
Post |
{ "query":{ "wildcard":{ "ManagerName":{ "value":"?*" , "boost":10 } } } } |
|
Terms 最低匹配查询已不再支持,需要使用bool查询 |
Post |
{ "query":{ "terms":{ "ManagerName":["富","宇","财","富"] ,"minimum_match": 1 } } } |
|
query_string +-前面注意要有一个空格 |
Post |
{ "query":{ "query_string":{ "query":" +ManagerName:财富广场 -ManagerName:广场" } } } |
过滤器
Filter 查询 Filter查询不同时支持bool、or、and、exists、missing查询 |
Post |
http://172.16.20.49:9200/zuhe/zuheentity/_search |
{ "filter": { "bool": {"should": [{"term":{"ManagerName":"世"}} ,{"term":{"ManagerName":"界"}} ], "must_not": {"term": {"ManagerName":"水"} } } } } |
Query 语义查询 |
Post |
http://172.16.20.49:9200/zuhe/zuheentity/_search |
{ "query": { "bool": {"should": [{"term":{"ManagerName":"世"}} ,{"term":{"ManagerName":"界"}} ], "must_not": {"term": {"ManagerName":"水"} } } } } |
Filter、query联合查询 |
{ "filter": { "bool": {"should": [{"term":{"ManagerName":"世"}} ,{"term":{"ManagerName":"界"}} ], "must": {"term": {"ManagerName":"水"} } } } ,"query": { "bool": {"should": [{"term":{"ManagerName":"世"}} ,{"term":{"ManagerName":"界"}} ], "must_not": {"term": {"ManagerName":"界"} } } } } |
高级查询:
首先建立mapping关系,表示在type1对应的文档中,包含一个obj1的对象;
{
"type1" : {
"properties" : {
"obj1" : {
"type" : "nested"
}
}
}
}
嵌套查询,
{
"query":{
"nested" : {
"path" : "obj1",
"query" : {
"bool" : {
"must" : [
{
"match" : {"obj1.name" : "善亮"}
}
]
}
}
}
}
}
父查询、子查询同样,先建立mapping关系;
Put
http://172.16.20.49:9200/testindex/
“”{
"mappings": {
"grouptype": {
"properties" : {
"groupid" : {
"type" : "long"
}
}
},
"person": {
"_parent": {
"type": "grouptype"
}
}
}
}
插入元素:
http://172.16.20.49:9200/testindex/person/1?parent=1
{
"name":"zhan san",
"age":"10"
}
查询父:
http://172.16.20.49:9200/testindex/grouptype/_search
{
"query": {
"has_child": {
"type": "person",
"query": {
"match": {
"age": 10
}
}
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
查询子:
http://172.16.20.49:9200/testindex/person/_search
{
"query": {
"has_parent": {
"type": "grouptype",
"query": {
"match": {
"groupname": "搜索组"
}
}
}
}
}
分组统计:
{
"query": {
"filtered": {
"filter": {
"missing": {
"field": "Zhlx"
}
}
}
},
"size": ,
"aggregations": {
"tag": {
"terms": {
"field": "Permit",
"size":
}
}
}
}
post
批量插入:
{ "index": { "_index": "user","_type": "userinfo","_id": "6321113681837248" } }
{"uid":"6321113681837248","sid":"10000017","displayname":"ZYH","level":"3","introduce":"Good Luck"}
{ "index": { "_index": "user","_type": "userinfo","_id": "1871112725585910" } }
{"uid":"1871112725585910","level":"4"}
{ "index": { "_index": "user","_type": "userinfo","_id": "5123094091554478" } }
{"uid":"5123094091554478","level":"24"}
{ "index": { "_index": "user","_type": "userinfo","_id": "7340313454673584" } }
{"uid":"7340313454673584","level":"27"}
{ "index": { "_index": "user","_type": "userinfo","_id": "2465111535617940" } }
{"uid":"2465111535617940","level":"25"}
{ "index": { "_index": "user","_type": "userinfo","_id": "7221114042211736" } }
{"uid":"7221114042211736","level":"21"}
{ "index": { "_index": "user","_type": "userinfo","_id": "3006113720930996" } }
post
批量更新:
{ "update": { "_index": "user","_type": "userinfo","_id": "6321113681837248" }}
{"doc":{"uid":"6321113681837248","sid":"10000017","displayname":"ZYH","level":"3","introduce":"Good Luck"},"upsert":{"uid":"6321113681837248","sid":"10000017","displayname":"ZYH","level":"3","introduce":"Good Luck"}}
查看分词器效果:
http://172.16.58.54:9200/_analyze?analyzer=standard&pretty=true&text=我是中国人"
http://www.cnblogs.com/xing901022/p/5339419.html
Elasticsearch基本操作的更多相关文章
- ElasticSearch 全文检索— ElasticSearch 基本操作
REST 简介-定义 REST (REpresentation State Transfer)描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy Fielding ...
- elasticsearch基本操作之--java基本操作 api
/** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ 默认进行了elasticsearch安装和ik安装, 超时配 ...
- elasticsearch基本操作之--使用QueryBuilders进行查询
/** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ QueryBuilder 是es中提供的一个查询接口, 可以 ...
- elasticsearch基本操作之--使用java操作elasticsearch
/** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ es 查询共有4种查询类型 QUERY_AND_FETCH: ...
- ElasticSearch基本操作(安装,索引的创建和删除,映射)
ElasticSearch基于Lucene的搜索服务器,支持分布式,提供REST接口,可用于云计算,可以实现实时搜索,开源免费.这时很官方的一句话,在使用之前,我们简单的介绍一下安装过程.在官网下载之 ...
- elasticsearch 基本操作
安装delete_by_query ,cd进/bin,执行./plugin install delete-by-query DELETE http://192.168.1.12:9200/dd ...
- ElasticSearch基础知识讲解
第一节 ElasticSearch概述 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTfull web接口.ElasticSea ...
- Elasticsearch笔记二之Curl工具基本操作
Elasticsearch笔记二之Curl工具基本操作 简介: Curl工具是一种可以在命令行访问url的工具,支持get和post请求方式.-X指定http请求的方法,-d指定要传输的数据. 创建索 ...
- ElasticSearch之安装及基本操作API
ElasticSearch 是目前非常流行的搜索引擎,对海量数据搜索是非常友好,并且在高并发场景下,也能发挥出稳定,快速特点.也是大数据和索搜服务的开发人员所极力追捧的中间件.虽然 ElasticSe ...
随机推荐
- GridView中超链接设置
<%# Eval("id") %>Bind方式 <%# Bind("id","~/info.aspx?id={0}" ...
- ssh myeclipse的bug
1 有时候复制完一个类的时候,myeclispe会少复制一些方法.很坑爹.复制的时候最好从新创建让后粘贴 2 有时候jsp页面经过修改该以后,在网页上显示的还是原来的页面,很坑爹.删掉tomcat然后 ...
- CODEVS 1817 灾后重建 Label:Floyd || 最短瓶颈路
描述 灾后重建(rebuild) B地区在地震过后,所有村庄都造成了一定的损毁,而这场地震却没对公路造成什么影响.但是在村庄重建好之前,所有与未重建完成的村庄的公路均无法通车.换句话说,只有连接着两 ...
- OSG中的HUD
OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...
- JavaScript事件对象【转】
一. 事件对象 事件处理三部分组成:对象.事件处理函数=函数.例如:单击文档任意处. 1.鼠标按钮 非 IE(W3C)中的 button 属性 0 表示主鼠标按钮(常规一般是鼠标左键) 1 表示中间的 ...
- mysql相似于oracle的to_char() to_date()方法
mysql日期和字符相互转换方法, date_format(date,'%Y-%m-%d') -------------->oracle中的to_char(); str_to_date(dat ...
- java web(一) 使用sql标签库+tomcat+mysql手动创建一个jsp练习总结
2016-09-0111:06:53 使用sql标签库+tomcat+mysql手动创建一个jsp 1. 1.1安装tomcat ...
- vbs下载者
一.VBS下载者: Set Post = CreateObject("Msxml2.XMLHTTP") Set Shell = CreateObject("Wscript ...
- redis集群搭建
1. Redis Cluster的架构图. (1)所有的redis节点彼此互联(PING-PONG机制),内部使用二进制协议优化传输速度和带宽. (2)节点的fail是通过集群 ...
- EF 关系规则(一对一、一对多、多对多...)
转自: http://www.cnblogs.com/dudu/archive/2011/07/11/ef_one-to-one_one-to-many_many-to-many.html Entit ...