博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Elastic Search(一)
阅读量:4917 次
发布时间:2019-06-11

本文共 4773 字,大约阅读时间需要 15 分钟。

一. 安装插件

  1. Marvel集群管理

    ```shell
    root@lj-ThinkPad-L460:~# sudo bin/plugin install license
    root@lj-ThinkPad-L460:~# sudo bin/plugin install marvel-agent

    访问 http://localhost:9200/_plugin/marvel/
    ```
  2. Kibana 4.5.1可视化

    root@lj-ThinkPad-L460:~# wget https://download.elastic.co/kibana/kibana/kibana-4.5.1-linux-x64.tar.gzroot@lj-ThinkPad-L460:~# vim  config/kibana.ymlSet the elasticsearch.url root@lj-ThinkPad-L460:~# ./bin/kibana 运行访问 http://yourhost.com:5601
  3. 启动es

    ./elasticsearch --cluster.name my_cluster_name --node.name my_node_name

二.快速入门

  1. 管理

    #1.cluster healthycurl 'localhost:9200/_cat/health?v'#2. nodes in our clustercurl 'localhost:9200/_cat/nodes?v'#3.list all indicescurl 'localhost:9200/_cat/indices?v'
  2. customer例子

    ```shell
    #1. create an index named "customer" and then list all the indexes again:
    ➜ ~ curl 'localhost:9200/_cat/indices?v'
    ➜ ~ curl 'localhost:9200/_cat/indices?v'

    #2. Let’s index a simple customer document into the customer index, "external" type, with an ID of 1

    ➜ ~ curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
    {
    "name": "John Doe"
    }'

    # ip:port/index name/type/id

    ➜ ~ curl -XGET 'localhost:9200/customer/external/1?pretty'
    {
    "_index" : "customer",
    "_type" : "external",
    "_id" : "1",
    "_version" : 1,
    "found" : true,
    "_source" : {
    "name" : "John Doe" # full json
    }
    }

    #3. delete the index that we just created

    # curl -X:///
    ➜ ~ curl -XGET 'localhost:9200/customer/external/1?pretty'

    #4. batch processing

    ➜ ~ curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
    {"index":{"_id":"1"}}
    {"name": "John ss" }
    {"index":{"_id":"2"}}
    {"name": "Jane Doe" }
    '
    ```

  3. bank例子

    #1. download json file : https://github.com/bly2k/files/blob/mas#2. load file➜  ~ curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"➜  ~ curl 'localhost:9200/_cat/indices?v'      health status index                   pri rep docs.count docs.deleted store.size pri.store.size yellow open   bank                      5   1       1000            0    442.1kb        442.1kb yellow open   .marvel-es-1-2016.06.14   1   1       4816           26      1.9mb          1.9mb yellow open   .marvel-es-data-1         1   1          4            2     12.2kb         12.2kb yellow open   .kibana                   1   1          1            0      3.1kb          3.1kb yellow open   customer                  5   1          2            0      6.5kb          6.5kb #3. search api➜  ~ curl 'localhost:9200/bank/_search?q=*&pretty'{  "took" : 89,        #time in milliseconds for Elasticsearch to execute the search  "timed_out" : false,     #if the search timed out or not  "_shards" : {            #how many shards were searched, as well as a count of the successful/failed searched shards    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {              #search results    "total" : 1000,       # total number of documents matching our search criteria    "max_score" : 1.0,    "hits" : [ {      "_index" : "bank",      "_type" : "account",      "_id" : "25",      "_score" : 1.0,      "_source" : {        "account_number" : 25,        "balance" : 40540,        "firstname" : "Virginia",        "lastname" : "Ayala",        "age" : 39,        "gender" : "F",        "address" : "171 Putnam Avenue",        "employer" : "Filodyne",        "email" : "virginiaayala@filodyne.com",        "city" : "Nicholson",        "state" : "PA"      }    }, {# instead of passing q=* in the URI, we POST a JSON-style query : Json Query DSL➜  ~ curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{  "query": { "match_all": {} }}'➜  ~ curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{  "query": { "match_all": {} },  "from": 10,  "size": 10,  "sort": { "balance": { "order": "desc" } },  "_source": ["account_number", "balance"]      #显示的字段}'#where条件➜  ~ curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{  "query": { "match": { "account_number": 20 } }}'# and or条件查询语法➜  ~ curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{  "query": {    "bool": {           "must": [           { "match": { "address": "mill" } },        { "match": { "address": "lane" } }      ]    }  }}'#"bool":bool型查询     #"must":and    "should":or   "must_not":neither..nor#范围查询➜  ~ curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{  "query": {    "bool": {      "must": { "match_all": {} },      "filter": {        "range": {          "balance": {            "gte": 20000,            "lte": 30000          }        }      }    }  }}' # "gte":大于   "lte":小于#group by#SELECT state, COUNT(*) FROM bank GROUP BY state ORDER BY COUNT(*) DESC➜  ~ curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{  "size": 0,  "aggs": {    "group_by_state": {      "terms": {        "field": "state"      }    }  }}'

转载于:https://www.cnblogs.com/72808ljup/p/5584452.html

你可能感兴趣的文章
SDUT 3346 数据结构实验之二叉树七:叶子问题
查看>>
正则表达式介绍
查看>>
linux 比较命令
查看>>
软件工程学习心得4
查看>>
车机HMI开发过程中的功能安全方案
查看>>
我要上蓝翔
查看>>
Ping pong(树状数组经典)
查看>>
Mysql 语句优化
查看>>
记一次面试
查看>>
例子:进度条
查看>>
二叉树
查看>>
kubernetes安装记录
查看>>
easyui 回车搜索
查看>>
SAP 使用SQL Trace(ST05)
查看>>
P4777 【模板】扩展中国剩余定理(EXCRT)&& EXCRT
查看>>
[PowerShell]Quote in String
查看>>
Workpress搭建经验 (ubuntu16.04+nginx+mysql+php7)
查看>>
Java List详解
查看>>
选择排序SelectSort
查看>>
一个案例深入Python中的__new__和__init__
查看>>