Elasticsearch搜索引擎常用命令

/index/ 查看指定索引的详细信息
/index/_search 查看指定索引下的数据

执行时先执行mapping_setting
然后执行 mapping.sh
ik_smark最少切分
ik_max_word则为细粒度的切分
/_aliases 获取或操作索引的别名
/index/type/创建或操作类型
/index/_mapping 创建活操作mapping
/index/_settings 创建或者操作设置
/index/_open 打开或指定关闭索引
/index/_colse 关闭执行索引
/index/_refresh 刷新索引
/index/_flush 刷新索引
index/_bluk?pretty 能支持多个操作 并返回json数据格式

_all 也可以在索引部分直接使用_all关键字代表匹配所有的索引:_all字段是把所有其它字段中的值,以空格为分隔符组成一个大字符串,然后被分析和索引,但是不存储,也就是说它能被查询,但不能被取回显示。

_all能让你在不知道要查找的内容是属于哪个具体字段的情况下进行搜索
curl -XPOST localhost:9200/_all/_search?pretty -d '{"query":{"match_all":{}}}'

插入数据curl -XPOST localhost:9200/test1/test/1 -d '{"name":"test1"}'

除了索引和替换文档,ES还支持更新文档。更新文档其实是先删除旧的文档,再索引新的文档。
如果想要更新文档内容,可以按照下面的方式进行:
curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
"doc": { "name": "Jane Doe" }
}'
删除文档:curl -XDELETE 'localhost:9200/customer/external/2?pretty'

获取数据:curl -xGET http://192.168.1.1:9201/xiaodu/question/_search?pretty=true

索引库名称必须要全部小写,不能以下划线开头,也不能包含逗号

通过查询API删除指定索引库下指定类型下的数据
curl -XDELETE 'http://localhost:9200/bjsxt/emp/_query?q=user:kimchy'

通过查询API删除多个索引库下多种类型下的数据
curl -XDELETE 'http://localhost:9200/bjsxt,index/emp,user/_query?q=user :kimchy'

或者删除所有索引库中的匹配的数据
curl -XDELETE 'http://localhost:9200/_all/_query?q=tag:wow'


curl -XPUT 'localhost:9200/customer'//创建索引
//插入数据
curl -XPUT 'localhost:9200/customer/external/1'-d '
{
"name": "John Doe"
}'
curl 'localhost:9200/customer/external/1'//查询数据
curl -XDELETE 'localhost:9200/customer'//删除索引


curl 'localhost:9200/bank/_search?q=*&pretty'其中bank是查询的索引名称,q后面跟着搜索的条件:q=*表示查询所有的内容
推荐使用以下这种 这种方式会把查询的内容放入body中,会造成一定的开销,但是易于理解。在平时的练习中,推荐这种方式。
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": { "match_all": {} }
}'
以上返回结果字段解析:took查询花费时间毫秒单位
time_out:标识查询是否超时 _shards:描述了查询分片的信息,查询了多少个分片、成功的分片数量、失败的分片数量等
hits:搜索的结果,total是全部的满足的文档数目,hits是返回的实际数目(默认是10)_score是文档的分数信息,与排名相关度有关,参考各大搜索引擎的搜索结果,就容易理解。
http://www.cnblogs.com/xing901022/p/4967796.html

 

 

创建索引:curl -XPUT http://localhost:9201/xiaodu

删除索引:curl -XDELETE http://localhost:9200/my

删除索引(结果为true:)curl -XDELETE 'localhost:9200/customer?pretty'
检查ES集群状态:curl localhost:9201/_cat/health?v
red:表示有些数据不可用
  yellow:表示所有数据可用,但是备份不可用
  green:表示一切正常

检查ES节点状态:curl localhost:9200/_cat/nodes?v

查询所有的索引:curl localhost:9200/_cat/indices?v
删除索引:curl -XDELETE localhost:9200/索引名字
查询索引:curl -XGET localhost:9200/索引名字/类型名字/id
创建索引和数据一条命令:curl -XPUT 'localhost:9200/index/type/1?pretty' -d'{"name":"qweqwe"}'
查看数据: curl -xPOST localhost:9200/index/type/1
curl -XPOST 123.57.8.252:9201/my/newtype/_search?pretty
curl -xGET localhost:9200/index/type/1
curl -xGET localhost:9200/index/type/_search?pretty
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' _bulk可以查看多个数据
查询固定字段信息curl -XPOST 'localhost:9200/indexa/type/_search?pretty' -d'{"query":{"match":{"name":"qweq"}}}'

这种方式会将数据放到body当中
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": { "match_all": {} }
}'

bool查询 可以把很多小查询组合成一个复杂的查询
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}'

 

查询返回的参数详解:
took:查询花费的时间 毫秒
time_out:标识查询是否超时
_shards:分片信息 查询了多少分片 成功多少分片 失败多少分片
_score 文档的分数信息
hits 搜索的结果
total全部数据的文档数目
hits返回的实际数目
_source包括数据的具体内容
not_analyzed则会将整个字段存储为关键词,常用于汉字短语、邮箱等复杂的字符串
analyzed则将会通过默认的standard分析器进行分析

posted @ 2017-05-19 10:09  yuancr  阅读(696)  评论(0)    收藏  举报