elasticsearch

elasticsearch使用


  • 查看集群健康情況

    curl 'localhost:9200/_cat/health?v'


  • 查看集群所有節(jié)點情況

    curl 'localhost:9200/_cat/nodes?v'


  • 查看集群中所有索引

    curl 'localhost:9200/_cat/indices?v'


  • 創(chuàng)建索引

    curl -XPUT 'localhost:9200/customer?pretty'


  • 檢索查詢文檔

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


  • 刪除索引

    curl -XDELETE 'localhost:9200/customer?pretty'


  • 修改文檔內(nèi)容

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


  • bluk 批量處理

    curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d ' {"update":{"_id":"1"}} {"doc": { "name": "John Doe becomes Jane Doe" } } {"delete":{"_id":"2"}} '


  • 外部數(shù)據(jù)json文件導(dǎo)入

    curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"


query language

  • 查詢所有

    { "query": { "match_all": {} } }


  • 分頁

    { "query": { "match_all": {} }, "from": 10, "size": 10 }'


  • 排序

    { "query": { "match_all": {} }, "sort": { "balance": { "order": "desc" } } }'


  • 字段查詢

    { "query": { "match": { "address": "mill" } } }'
    { "query": { "match_phrase": { "address": "mill lane" } } }


  • boolen查詢

    { "query": { "bool": { "must": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }
    { "query": { "bool": { "must_not": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }
    {
    "query": {
    "bool": {
    "must": [
    { "match": { "age": "40" } }
    ],
    "must_not": [
    { "match": { "state": "ID" } }
    ]
    }
    }
    }


  • range query

    { "query": { "bool": { "must": { "match_all": {} }, "filter": { "range": { "balance": { "gte": 20000, "lte": 30000 } } } } } }


  • 分組統(tǒng)計查詢

    { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state" } } } }


  • 多字段分組

    { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } }


  • 分組后求平均

    { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state", "order": { "average_balance": "desc" } }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } }


  • 根據(jù)范圍分組

    { "size": 0, "aggs": { "group_by_age": { "range": { "field": "age", "ranges": [ { "from": 20, "to": 30 }, { "from": 30, "to": 40 }, { "from": 40, "to": 50 } ] }, "aggs": { "group_by_gender": { "terms": { "field": "gender" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } } }


-java api 手冊

https://legacy.gitbook.com/book/quanke/elasticsearch-java/details

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容