elasticsearch 安装和 基本操作命令

1.找到该目录下的如下war包,放到Tomcat中的webapps中,当然如果我们访问它会自动解压
2.将jar包放入Tomcat的lib包中 lib包的路径如下:solr-4.9.1\example\lib\ext
3.修改solr项目中的WEB-INF下的web.xml文件的solrhome,如下:
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/usr/local/solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
4.在该目录下创建一个solr.xml文件,如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<solr> </solr>
并且copy solr-4.9.1\example\solr 下的其他文件

配置后在浏览器中访问 IP:9100


1.创建索引
curl -XPUT http://localhost:9200/index

2.创建索引
curl -XPUT http://localhost:9200/myindex?pretty
其他方式创建索引库
curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/indexwb3?pretty' -d '{
"settings":{
"index":{
"number_of_shards":2,
"number_of_replicas":5
}
}
}'

3.查看索引
curl -XGET http://localhost:9200/_cat/indices?v

4.插入数据
原生Ajax的时候,发送post请求,先决要素,就是必须有Content-Type:
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/indexwb2/product/p1 -d '{
"name":"mac",
"price":20000,
"description":"苹果笔记本",
"attr":["computer","高端"]
}'

5.查询数据
根据指定的条件,筛选部分的field进行展示
_search=name,age
_search_include 包含
_search_exclude 排除

_search=false //不显示_search中的文本
id/_search _index _type _id 不显示,只显示_source内容


6.修改数据
ES可以在操作中指定version参数,如:
curl -H "Content-Type: application/json" -XPOST http://localhost:9200/myindex/product/p1
/_update?version=4 -d '{ "doc":{ "name":"新版Mac222", "price":15200 } }'
Tip:版本必须匹配

7.删除数据
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/myindex/product/p3 -d '{
"name":"风扇",
"price":20,
"description":"手拿式电风扇",
"attr":["风大","体积小"]
}'
8.删除索引
curl -XDELETE http://localhost:9200/myindex/product/p1?pretty
--------------------
9.简单查询
curl -XGET 'http://localhost:9200/myindex/product/_search?q=name:mac第四次&q=price:2000&pretty'
分页查询:
curl -XGET 'http://localhost:9200/myindex/product/_search?size=2&from=2&pretty'

猜你喜欢

转载自www.cnblogs.com/xu06123/p/9356026.html