狼愛上貍

          我胡漢三又回來了

          elasticsearch的基本用法

          開始學(xué)習(xí)使用 elasticsearch, 把步驟記錄在這里:

          最大的特點(diǎn):
          1. 數(shù)據(jù)庫的 database, 就是  index
          2. 數(shù)據(jù)庫的 table,  就是 tag
          3. 不要使用browser, 使用curl來進(jìn)行客戶端操作.  否則會出現(xiàn) java heap ooxx...

          curl:  -X 后面跟 RESTful :  GET, POST ...
          -d 后面跟數(shù)據(jù)。 (d = data to send)

          1. create: 

          指定 ID 來建立新記錄。 (貌似PUT, POST都可以)
          $ curl -XPOST localhost:9200/films/md/2 -d '
          { "name":"hei yi ren", "tag": "good"}'

          使用自動(dòng)生成的 ID 建立新紀(jì)錄:
          $ curl -XPOST localhost:9200/films/md -d '
          { "name":"ma da jia si jia3", "tag": "good"}'

          2. 查詢:
          2.1 查詢所有的 index, type:
          $ curl localhost:9200/_search?pretty=true

          2.2 查詢某個(gè)index下所有的type:
          $ curl localhost:9200/films/_search

          2.3 查詢某個(gè)index 下, 某個(gè) type下所有的記錄:
          $ curl localhost:9200/films/md/_search?pretty=true

          2.4 帶有參數(shù)的查詢: 
          $ curl localhost:9200/films/md/_search?q=tag:good
          {"took":7,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"film","_type":"md","_id":"2","_score":1.0, "_source" :
          { "name":"hei yi ren", "tag": "good"}},{"_index":"film","_type":"md","_id":"1","_score":0.30685282, "_source" :
          { "name":"ma da jia si jia", "tag": "good"}}]}}

          2.5 使用JSON參數(shù)的查詢: (注意 query 和 term 關(guān)鍵字)
          $ curl localhost:9200/film/_search -d '
          {"query" : { "term": { "tag":"bad"}}}'

          3. update 
          $ curl -XPUT localhost:9200/films/md/1 -d { ...(data)... }

          4. 刪除。 刪除所有的:
          $ curl -XDELETE localhost:9200/films

          traceback:
          http://sg552.iteye.com/blog/1567047

          posted on 2015-07-20 15:45 狼愛上貍 閱讀(334) 評論(0)  編輯  收藏 所屬分類: elasticsearch

          主站蜘蛛池模板: 南平市| 富宁县| 青河县| 德钦县| 共和县| 宁化县| 鹤壁市| 泰来县| 汝阳县| 桐梓县| 平利县| 康平县| 长兴县| 石台县| 仙游县| 廊坊市| 前郭尔| 盐山县| 岑巩县| 古丈县| 利川市| 嵊州市| 静海县| 江口县| 宁武县| 吉木乃县| 安龙县| 望都县| 新津县| 乌鲁木齐市| 安溪县| 峨眉山市| 许昌市| 曲沃县| 寻乌县| 平原县| 田东县| 平陆县| 阜新| 台中市| 太原市|