码迷,mamicode.com
首页 > 其他好文 > 详细

ES使用心得

时间:2020-01-02 15:38:37      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:pretty   模糊查询   名称   封装   lin   请求   window   refresh   ctr   

目录

启动 2

检测启动是否成功 2

Post 192.168.2.29:9200/twitter/_search?routing=kimchy 2

Post 192.168.2.29:9200/twitter/_search 3

192.168.2.29:9200/bp_view/_search 5

POST /cool-user-index/_delete_by_query 7

封装工具介绍 8

服务 8

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Elasticsearch 全文检索引擎

启动

 

检测启动是否成功

 

http://localhost:9200/?pretty

 

索引/请求方式/类型(指定类别)

Post 192.168.2.29:9200/twitter/_search?routing=kimchy

{

    "error": {

        "root_cause": [

            {

                "type": "index_not_found_exception",

                "reason": "no such index",

                "resource.type": "index_or_alias",

                "resource.id": "twitter",

                "index_uuid": "_na_",

                "index": "twitter"

            }

        ],

        "type": "index_not_found_exception",

        "reason": "no such index",

        "resource.type": "index_or_alias",

        "resource.id": "twitter",

        "index_uuid": "_na_",

        "index": "twitter"

    },

    "status": 404

}



Post 192.168.2.29:9200/twitter/_search

{

    "query": {

        "bool" : {

            "must" : {

                "query_string" : {

                    "query" : "some query string here"

                }

            },

            "filter" : {

                "term" : { "user" : "kimchy" }

            }

        }

    }

}

未命中时返回

{

    "took": 101,

    "timed_out": false,

    "_shards": {

        "total": 5,

        "successful": 5,

        "skipped": 0,

        "failed": 0

    },

    "hits": {

        "total": 0,

        "max_score": null,

        "hits": []

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Post 192.168.2.29:9200/twitter/_search

{

    "query": {

        "bool" : {

            "must" : {

                "query_string" : {

                    

                }

            }

 

        }

    }

}

 

不能没有条件

{

    "error": {

        "root_cause": [

            {

                "type": "parsing_exception",

                "reason": "[query_string] must be provided with a [query]",

                "line": 8,

                "col": 17

            }

        ],

        "type": "parsing_exception",

        "reason": "[query_string] must be provided with a [query]",

        "line": 8,

        "col": 17

    },

    "status": 400

}

 

 

 

 

 

 

 

 

 

命中

192.168.2.29:9200/bp_view/_search

 

{

"from" : 2, //请求页数

"size": 1, //每页数量

    "query": {

         "match_all" : {} //全匹配

    }

}

 

{

    "took": 38,

    "timed_out": false,

    "_shards": {

        "total": 5,

        "successful": 5,

        "skipped": 0,

        "failed": 0

    },

    "hits": {

        "total": 10140, //总条数

        "max_score": 1.0,

        "hits": [ //数据列表

            {。。。}

]

}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

模糊查询

Post 192.168.2.29:9200/bp_view/_search

 

{

 

  "query": {

 

    "bool": {

 

      "must":{"match":{"title":"战"}} //模糊字段

 

    }

 

  }

 

}

 

删除其中不包含的id

POST /cool-user-index/_delete_by_query

{

  "query": {

    "bool": {

      "must_not": [

        {

          "ids": {

            "values": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,21,22,23,24,25,26,27,29,30,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,54,58,59,60,61,63,64,75,76,77,78,79,80,81,82,83,84,85,86,100,101,102,103,104,105,106,107,110,111,129,134,135,136,140,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184]

          }

        }

      ]

    }

  }

}

 

 

 

 

删除其中包含的id

POST /cool-user-index/_delete_by_query

{

  "query": {

    "bool": {

      "must": [

        {

          "ids": {

            "values": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,21,22,23,24,25,26,27,29,30,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,54,58,59,60,61,63,64,75,76,77,78,79,80,81,82,83,84,85,86,100,101,102,103,104,105,106,107,110,111,129,134,135,136,140,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184]

          }

        }

      ]

    }

  }

}

 

 

 

RequestReturnUtil 接口调用工具类

 

 Delate 192.168.2.29:9200/bp_view/1 //删除数据

POST 192.168.2.29:9200/bp_view/_delete_by_query?refresh&slices=5&pretty { "query": { "match_all": {} } } //清空数据

 

 

封装工具介绍
void getParmOfdeleteCataByID(List<String> list)

参数传入ids删除编目数据

 

void getParmOfdeleteCollectionByID(List<String> list)

参数传入ids删除典藏数据

 

void addCollection(String id ,String json)

参数传入id和典藏参数

 

void addCata(String id ,String json)

参数传入id和典藏参数

 

 

 

 

服务

 

Windows

启动时通过cmd直接在elasticsearchbin目录下执行elasticsearch

这样直接启动的话集群名称会默认为elasticsearch,节点名称会随机生成。

停止就直接在cmd界面按Ctrl+C

其实我们也可以将elasticsearch设置为windows系统服务:

elasticsearchbin目录下有一个elasticsearch-service.bat

进入bin目录下执行:

 

elasticsearch-service.bat install

1

 

然后在系统服务中可以看到Elasticsearch已成为系统服务。

 

elasticsearch-service.bat后面还可以执行这些命令

install: 安装Elasticsearch服务

remove: 删除已安装的Elasticsearch服务

start: 启动Elasticsearch服务

stop: 停止服务

ES使用心得

标签:pretty   模糊查询   名称   封装   lin   请求   window   refresh   ctr   

原文地址:https://www.cnblogs.com/kxhbd/p/12133090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!