狼愛上貍

          我胡漢三又回來了

          elasticsearch的基本用法

          開始學習使用 elasticsearch, 把步驟記錄在這里:

          最大的特點:
          1. 數據庫的 database, 就是  index
          2. 數據庫的 table,  就是 tag
          3. 不要使用browser, 使用curl來進行客戶端操作.  否則會出現 java heap ooxx...

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

          1. create: 

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

          使用自動生成的 ID 建立新紀錄:
          $ 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 查詢某個index下所有的type:
          $ curl localhost:9200/films/_search

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

          2.4 帶有參數的查詢: 
          $ 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參數的查詢: (注意 query 和 term 關鍵字)
          $ 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

          主站蜘蛛池模板: 巩留县| 眉山市| 甘谷县| 苍山县| 江门市| 宁津县| 商洛市| 温州市| 即墨市| 东兴市| 沅陵县| 赫章县| 芷江| 延长县| 行唐县| 大关县| 沙坪坝区| 正宁县| 彭山县| 安宁市| 即墨市| 万荣县| 汉中市| 增城市| 肥乡县| 宾川县| 静安区| 乌鲁木齐市| 加查县| 云和县| 平塘县| 互助| 衡南县| 永和县| 井冈山市| 盐亭县| 峨眉山市| 紫云| 岫岩| 肃南| 兴和县|