您的位置:首页 > 其它

elasticsearch 常用命令总结

2018-01-09 17:16 375 查看
1.创建一个索引 (index 是索引的名字)

curl -XPUT http://localhost:9200/indexName
2.映射相光
#创建一个映射
curl -XPOST http://localhost:9200/quanzi/fulltext/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}'
#查看映射
curl -XGET "http://localhost:9200/quanzi/_mapping/fulltext?pretty"
#新增一个字段
curl -XPUT "http://localhost:9200/quanzi/_mapping/fulltext"; -H 'Content-Type: application/json' -d'
{

"properties": {
"tags4": {
"type": "keyword"
}
}

}'

3.分析器的测试
#老版 http://localhost:9200/quanzi/_analyze?text=糜烂胎停宫腔粘连&tokenizer=ik_smart #6.0以上版本
curl -XGET "http://localhost:9200/_analyze"; -H 'Content-Type: application/json' -d'
{
"analyzer" : "ik_max_word",
"text" : "糜烂胎停宫腔粘连”
}’

4.索引的添加和修改
#添加一个文档
curl -XPUT "http://localhost:9200/quanzi/article/2"; -H 'Content-Type: application/json' -d'
{
"content":"中国的女子很多有这个问题",
"tags":["试管","高龄"]
}'

#更新部分数据
上面的脚本是对所有的文档都起作用,这里讲解下如何只对部分文档进行修改。使用doc可以实现简单的递归合并、内部合并、替换KV以及数组。
curl -XPOST "http://localhost:9200/quanzi/article/1/_update"; -H 'Content-Type: application/json' -d'
{
"doc":{
"tags":["多囊","高龄"]}
}'
如果同时使用了doc和script,那么doc的操作会自动忽略。因此最好是把特殊的操作也放在脚本中。

5.删除的操作
#.批量删除文档
curl -XPOST "http://localhost:9200/feeds/_delete_by_query"; -H 'Content-Type: application/json' -d'
{

"query": {
"match": {
"type": "article"
}
}
}’
#.删除单个文档
curl -XDELETE "http://localhost:9200/feeds/feed/article_59f9385843707f81a34a6540”;
#.删除索引
curl -XDELETE "http://localhost:9200/quanzi"
curl -XDELETE "http://localhost:9200/index_*";
curl -XDELETE "http://localhost:9200/quanzi,test";
curl -XDELETE "http://localhost:9200/_all";
curl -XDELETE "http://localhost:9200/*";

6.批量导入(文件和控制台在同一服务器上操作)
curl -H "Content-Type: application/json;charset=UTF-8" -XPOST 'http://localhost:9200/_bulk?pretty' --data-binary @word.json
#word.json 的格式如下:
导入格式如下:
{ "index" : { "_index" : "association", "_type" : "word", "_id" : "doctor_1111" }}
{"content":"杨静","type":2,"frequency":1,"location":"","code":"11111","hospital":{"name":"解放军第306医院","id":"11111"}}
{ "index" : { "_index" : "association", "_type" : "word", "_id" : "doctor_2222" }}
{"content":"兰永连","type":2,"frequency":1,"location":"","code":"2222","hospital":{"name":"北京妇产医院","id":"22222"}}
{ "index" : { "_index" : "association", "_type" : "word", "_id" : "doctor_1425276716764" }}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: