文检索 ElasticSearch
介绍:https://www.elastic.co/cn/products/
官方下载:https://www.elastic.co/downloads/elasticsearch
官方安装参考:https://www.elastic.co/guide/en/elasticsearch/reference/6.7/install-elasticsearch.html
安装参考:https://www.jianshu.com/p/5fd19b02e093
安装参考:https://blog.csdn.net/sinat_30276961/article/details/82872672#1elastic_9
最终版本采用 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/tree/master IK安装文档
https://github.com/superdreams/elasticsearch-analysis-ik/releases
下载 https://github.com/superdreams/elasticsearch-analysis-ik/archive/v6.7.0.zip 解压放入/usr/share/elasticsearch/plugins/ik/下
创建 mapping
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/blog/doc/1 -d '
{
"id":"1",
"title":"伟大的中国",
"Author":"李白",
"Subject":"语文",
"Content":"w欢迎来到中国",
"postdate ":"2008-08-08"
}'
全文分词检索高亮使用
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安装
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html
https://www.elastic.co/guide/cn/elasticsearch/php/current/_installation_2.html
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
JDBC
https://github.com/jprante/elasticsearch-jdbc
授权:GRANT ALL PRIVILEGES ON *.* TO ‘username’@‘%’ IDENTIFIED BY 'password’;
es创建索引
curl -XPUT "localhost:9200/student/doc/1?pretty" -H 'Content-Type: application/json' -d'{"id":"1","title":"wei da de zhong guo","Author":"libai","Subject":"china","Content":"welecome to china","postdate ":"2008-08-08"}'
curl -XPUT "localhost:9200/student/doc/2?pretty" -H 'Content-Type: application/json' -d'{"id":"2","title":"伟大的中国","Author":"李白","Subject":"语文","Content":"w欢迎来到中国","postdate ":"2008-08-08"}'
curl -XPUT "localhost:9200/student/doc/3?pretty" -H 'Content-Type: application/json' -d'{"id":"3","title":"中国美食","Author":"巴拉巴拉","Subject":"文化","Content":"中国的食物超级好吃","postdate ":"2008-08-08"}'
curl -XPUT "localhost:9200/student/doc/4?pretty" -H 'Content-Type: application/json' -d'{"id":"4","title":"中国造船业","Author":"巴拉巴拉","Subject":"文化","Content":"中国制造","postdate ":"2008-08-09"}'
curl -XPUT "localhost:9200/student/doc/5?pretty" -H 'Content-Type: application/json' -d'{"id":"5","title":"啦啦啦阿道夫地方","Author":"深V非人防变得更巴尔","Subject":"反而阿尔","Content":"的飞洒发","postdate ":"2008-08-09"}'
ki创建索引(put)
curl -XPUT http://localhost:9200/blog/doc/9 -d '
{
"id":"9",
"title":"ejwe",
"Author":"李白",
"Subject":"语文",
"Content":"w欢迎来到中国",
"postdate ":"2008-08-08"
}'
curl -XPUT http://localhost:9200/blog/doc/2 -d '
{
"id":"2","title":"中国美食","Author":"巴拉巴拉","Subject":"文化","Content":"中国的食物超级好吃","postdate ":"2008-08-08"
}'
curl -XPUT http://localhost:9200/blog/doc/3 -d '
{
"id":"3",
"title":"中国自造的轮船",
"Author":"啦啦",
"Subject":"人文",
"Content":"中国自造棒棒哒,哈哈哈哈哈",
"postdate ":"2019-08-08"
}'
curl -XPUT http://localhost:9200/blog/doc/4 -d '
{
"id":"4",
"title":"伟大的中国",
"Author":"李白",
"Subject":"语文",
"Content":"w欢迎来到中国",
"postdate ":"2008-08-08"
}'
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/blog/doc/5 -d '
{
"id":"5",
"title":"巴啦啦能量",
"Author":"哇咔啦",
"Subject":"变身",
"Content":"我是来时黑魔仙",
"postdate ":"2018-08-08"
}'
ki更新索引(post)
curl -XPOST http://localhost:9200/blog/doc/8 -d '{"doc":{
"title":"巴啦啦能量",
"Author":"哇咔啦",
"Subject":"变身",
"Content":"啦啦啦啦啦啦啦",
"postdate ":"2018-08-08"}}'
查新搜索一个(get)
curl -XGET http://localhost:9200/blog/doc/3?pretty
删除索引(delete)
curl -XDELETE http://localhost:9200/blog/doc/3
全文检索
curl -XGET http://www.dawenwen.cn:9200/blog/_search?q=title:%E4%B8%AD%E5%9B%BD&pretty
curl -XGET http://111.231.98.85:9200/blog/_search?q=title:中国&pretty
查看全部的数据
curl -XGET http://111.231.98.85:9200/blog/_search?pretty