使用 postman 工具测试或者在代码中发送请求
CentOS7.4安装ElasticSearch7.3.0
一、创建索引 cn_kj288 可以多个建多个
接口 PUT Headers Content-Type:application/json;charset=utf-8
http://127.0.0.1:9200/cn_kj288
返回值
{"acknowledged":true,"shards_acknowledged":true,"index":"cn_kj288"}
二、查询 mapping
接口 GET Headers Content-Type:application/json;charset=utf-8
http://127.0.0.1:9200/cn_kj288/_mapping?pretty
返回值
{"cn_kj288":{"mappings":{}}}
三、插入数据
接口 POST Headers Content-Type:application/json;charset=utf-8
http://127.0.0.1:9200/cn_kj288/doc?
准备好的数据
{"name":"张三","phone":"15874785200","sex":"男"}
{"name":"张三老婆","phone":"13678456666","sex":"女"}
{"name":"张三表哥","phone":"13678456666","sex":"男"}
{"name":"张三表妹","phone":"17707465753","sex":"女"}
{"name":"张三小姨子","phone":"19949363586","sex":"女"}
{"name":"李四","phone":"13527526566","sex":"男"}
{"name":"李四老婆","phone":"13522335566","sex":"女"}
{"name":"李四小姨子","phone":"13522335566","sex":"女"}
{"name":"王婆老公是张三","phone":"13522335566","sex":"女"}
{"name":"王五","phone":"13543535566","sex":"男"}
{"name":"王五老婆","phone":"13522335566","sex":"女"}
{"name":"王五表哥","phone":"13522335566","sex":"男"}
{"name":"隔壁老王表哥叫李四","phone":"13522335566","sex":"男"}
四、全文查询
接口 POST Headers Content-Type:application/json;charset=utf-8
http://127.0.0.1:9200/cn_kj288/doc/_search?pretty
五、条件查询
接口 POST Headers Content-Type:application/json;charset=utf-8
http://127.0.0.1:9200/cn_kj288/_search?pretty
1.返回指定字段
{"_source": ["phone","sex"]}
2.短语精准匹配
{"query":{"match_phrase":{"name":"王五"}}}
3.精准查询
{"query":{"term":{"phone.keyword":"17707465753"}}}
4.分词查询
{"query":{"match":{"name":"婆五"}}}
5._source query 组合使用 分词查询返回指定字段
{"query":{"match":{"name":"婆五"}},"_source": ["name","phone"]}
总结:以上是在cn_kj288 索引下的一些基本用法
如果想查询全部索引下的数据 将接口修改一下即可,去掉 /cn_kj288
http://127.0.0.1:9200/_search?pretty