elasticsearch基础命令
全文检索 ElasticSearch
最终版本采用 word 文档
ES REST CRUD常用操作:
1、测试服务正常开启:
curl -XGET "localhost:9200"
2、查看索引列表:
curl -XGET "localhost:9200/_cat/nodes?v"
3、查看索引列表:
curl -XGET "localhost:9200/_cat/indices?v"
4、创建索引
curl -XPUT "localhost:9200/customer?pretty"
5、索引删除
curl -XDELETE "localhost:9200/customer?pretty"
6、数据获取
curl -XGET "localhost:9200/goods/_search?pretty"
7、文档创建
curl -XPUT "localhost:9200/goods/_doc/1?pretty" -H 'Content-Type: application/json' -d'{"title": "orange","size": "33","color": "orange"}'
curl -XPOST "localhost:9200/goods/_doc/?pretty" -H 'Content-Type: application/json' -d'{"title": "banana","size": "55","color": "yellow"}'
curl -XPUT "localhost:9200/goods/_doc/3?pretty" -H 'Content-Type: application/json' -d'{"title": "apple", "size": "22","color": "red"}'
8、文档更新
curl -XPUT "localhost:9200/goods/_doc/3?pretty" -H 'Content-Type: application/json' -d'{"title": "apple", "size": "88","color": "green"}'
9、文档获取
curl -XGET "localhost:9200/goods/_doc/3?pretty"
10、文档删除
curl -XDELETE "localhost:9200/goods/_doc/3?pretty"
Esearch查询 URI方式
curl -XGET "localhost:9200/goods/_search?q=title:orange&pretty"
curl -XGET "localhost:9200/goods/_search?q=orange&pretty"
Esearch查询 DSL方式
多文档查询
分词,查询 ,ik分词:
下载 https://github.com/superdreams/elasticsearch-analysis-ik/archive/v6.7.0.zip 解压放入/usr/share/elasticsearch/plugins/ik/下
创建 mapping
curl -XPOST http://localhost:9200/news/fulltext/_mapping -H 'Content-Type:application/json' -d '
{
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
全文分词检索高亮使用
curl -XPOST http://localhost:9200/news/fulltext/_search?pretty -H 'Content-Type:application/json' -d'
{
"query" : { "match" : { "content" : "渔船每天行驶多远" }},
"highlight" : {
"pre_tags" : ["<em1>", "<em2>"],
"post_tags" : ["</em1>", "</em2>"],
"fields" : {
"content" : {}
}
}
}'
sort
stored_fields:
curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"stored_fields" : [],
"query" : {
"term" : { "user" : "kimchy" }
}
}'
PHP安装
JDBC
授权:GRANT ALL PRIVILEGES ON *.* TO ‘username’@‘%’ IDENTIFIED BY 'password’;