export elasticsearchwebaddress=localhost:9200
# 1. Add document
curl -X PUT "$elasticsearchwebaddress/megacorp/employee/1" -d '
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}'

curl -X DELETE "$elasticsearchwebaddress/megacorp/employee/1" -d '
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}'

curl -X PUT "$elasticsearchwebaddress/megacorp/employee/2" -d '
{
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}'

curl -X PUT "$elasticsearchwebaddress/megacorp/employee/3" -d '
{
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}'

# 2. Retrive information
curl -X GET "$elasticsearchwebaddress/megacorp/employee/1"


curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search"

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search?q=last_name:Smith"

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
    "query" : {
        "match" : {
            "last_name" : "Smith"
        }
    }
}'

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
    "query" : {
        "filtered" : {
            "filter" : {
                "range" : {
                    "age" : { "gt" : 30 } 
                     }
                },
            "query" : {
                "match" : {
                    "last_name" : "smith" 
                      }
               }
          }
     }
}'

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
    "query" : {
        "match" : {
            "about" : "rock climbing"
        }
    }
}'

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    }
}'

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    },
    "highlight": {
        "fields" : {
            "about" : {}
        }
    }
}'

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
  "aggs": {
    "all_interests": {
      "terms": { "field": "interests" }
    }
  }
} '

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
  "query": {
    "match": {
      "last_name": "smith"
    }
  },
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}'

curl -X GET "$elasticsearchwebaddress/megacorp/employee/_search" -d '
{
    "aggs" : {
        "all_interests" : {
            "terms" : { "field" : "interests" },
            "aggs" : {
                "avg_age" : {
                    "avg" : { "field" : "age" }
                }
            }
        }
    }
}'

curl -X GET "$elasticsearchwebaddress/_cluster/health"
curl -X GET "$elasticsearchwebaddress/_cluster/health?pretty"

curl -X PUT "$elasticsearchwebaddress/blogs" -d '
{
   "settings" : {
      "number_of_shards" : 3,
      "number_of_replicas" : 1
   }
}'
curl -X PUT "$elasticsearchwebaddress/website/blog/123" -d '
{
  "title": "My first blog entry",
  "text":  "Just trying this out...",
  "date":  "2014/01/01"
}'
curl -i -X GET http://localhost:9200/website/blog/124?pretty

curl -i -X GET http://localhost:9200/website/blog/123?pretty\&_source=title,text
curl -i -X GET http://localhost:9200/website/blog/123?pretty

curl -i -X GET http://localhost:9200/website/blog/123/_source

#Checking whether document exists.
curl -i -XHEAD http://localhost:9200/website/blog/123

#Updating a document
curl  -X PUT $elasticsearchwebaddress/website/blog/123 -d '
{
  "title": "My first blog entry",
  "text":  "I am starting to get the hang of this...",
  "date":  "2014/01/02"
}'

curl -X PUT "$elasticsearchwebaddress/website/blog/124" -d '
{
  "title": "My first blog entry",
  "text":  "Just trying this out...",
  "date":  "2014/01/01"
}'

curl -X DELETE $elasticsearchwebaddress/website/blog/123
curl -X DELETE $elasticsearchwebaddress/website/blog/1232

curl  -X PUT $elasticsearchwebaddress/website/blog/1232 -d '
{
  "title": "My first blog entry",
  "text":  "I am starting to get the hang of this...",
  "date":  "2014/01/02"
}'

curl  -X PUT $elasticsearchwebaddress/website/blog/1/_create -d '
{
  "title": "My first blog entry",
  "text":  "Just trying this out..."
}'

curl  -X PUT $elasticsearchwebaddress/website/blog/1?version=1 -d '
{
  "title": "My first blog entry",
  "text":  "Starting to get the hang of this..."
}'

curl  -X PUT $elasticsearchwebaddress/website/blog/2?version=5\&version_type=external -d '
{
  "title": "My first external blog entry",
  "text":  "Starting to get the hang of this..."
}'

curl  -X PUT $elasticsearchwebaddress/website/blog/2?version=10\&version_type=external -d '
{
  "title": "My first external blog entry",
  "text":  "This is a piece of cake..."
}'

#Partial update document

curl -X GET $elasticsearchwebaddress/website/blog/1?pretty
curl -X POST $elasticsearchwebaddress/website/blog/1/_update -d '
{
   "doc" : {
      "tags" : [ "testing" ],
      "views": 0
   }
}'

#Use scripts to update the value
curl -X POST $elasticsearchwebaddress/website/blog/1/_update -d '
{
   "script" : "ctx._source.views+=1"
}'

curl -X GET $elasticsearchwebaddress/website/blog/1?pretty
curl -X POST $elasticsearchwebaddress/website/blog/1/_update -d '
{
   "script" : "ctx._source.tags+=new_tag",
   "params" : {
      "new_tag" : "search"
   }
}'

curl -X GET $elasticsearchwebaddress/website/blog/1?pretty

curl -X POST $elasticsearchwebaddress/website/blog/1/_update -d "
{
   \"script\" : \"ctx.op = ctx._source.views == count ? 'delete' : 'none'\",
    \"params\" : {
        \"count\": 1
    }
}"

#upset
#cannot found 
curl -X GET $elasticsearchwebaddress/website/pageviews/1?pretty

curl -X POST $elasticsearchwebaddress/website/pageviews/1/_update -d '
{
   "script" : "ctx._source.views+=1",
   "upsert": {
       "views": 1
   }
}'

curl -X GET $elasticsearchwebaddress/website/pageviews/1?pretty

curl -X POST $elasticsearchwebaddress/website/pageviews/1/_update?retry_on_conflict=5 -d '
{
   "script" : "ctx._source.views+=1",
   "upsert": {
       "views": 0
   }
}'

#Retrieve multiple documents through multiple requests.
curl -X GET $elasticsearchwebaddress/_mget?pretty -d '
{
   "docs" : [
      {
         "_index" : "website",
         "_type" :  "blog",
         "_id" :    2
      },
      {
         "_index" : "website",
         "_type" :  "pageviews",
         "_id" :    1,
         "_source": "views"
      }
   ]
}'

curl -X GET $elasticsearchwebaddress/website/blog/_mget?pretty -d '
{
   "docs" : [
      { "_id" : 2 },
      { "_type" : "pageviews", "_id" :   1 }
   ]
}'

curl -X GET $elasticsearchwebaddress/website/blog/_mget?pretty -d '
{
   "ids" : [ "2", "1" ]
}'

#bulk API allows us to make multiple create, index, update or delete requests in a single step.
curl -X POST $elasticsearchwebaddress/_bulk -d '
{ "delete": { "_index": "website", "_type": "blog", "_id": "123" }} 
{ "create": { "_index": "website", "_type": "blog", "_id": "123" }}
{ "title":    "My first blog post" }
{ "index":  { "_index": "website", "_type": "blog" }}
{ "title":    "My second blog post" }
{ "update": { "_index": "website", "_type": "blog", "_id": "123", "_retry_on_conflict" : 3} }
{ "doc" : {"title" : "My updated blog post"} }
'
curl -X GET $elasticsearchwebaddress/website/blog

curl operate elasticsearch的更多相关文章

  1. 使用cURL尝试ElasticSearch

    测试环境:debian 9官网提供了 deb,rpm,源码下载 官方下载地址:https://www.elastic.co/downloads/elasticsearch 通过源码安装会遇到一些小问题 ...

  2. Curl操作Elasticsearch的常用方法

    Elasticsearch对于文档操作,提供了以下几种API,本文就说明如何使用curl方式来调用这些API. API种类 单文档操作API 1.* Index API 索引文档 * 为文档创建索引 ...

  3. elasticsearch(5) curl 操作elasticsearch

    创建索引之前可以对索引做初始化操作, 比如指定shards数量以及replicas的数量.     library为索引的名称 CURL -XPUT 'http://192.168.1.10:9200 ...

  4. Curl实现ElasticSearch的增删改查

    一.添加数据(laravel必须安装Curl扩展) $data = [ 'username'=>"张三", 'sex'=>"女", 'age'=&g ...

  5. window下使用curl操作elasticsearch

    1.下载curlzip,https://curl.haxx.se/download.html; 2.解压,在bin文件夹中找到curl.exe,右键“以管理员身份运行”,cmd e: 换盘符:出现E: ...

  6. Elasticsearch之CURL命令的DELETE

    也可以看我写的下面的博客 Elasticsearch之curl删除 Elasticsearch之curl删除索引库 删除,某一条数据,如下 [hadoop@master elasticsearch-] ...

  7. Elasticsearch【JAVA REST Client】客户端操作

    ES系统作为集群,环境搭建非常方便简单. 现在在我们的应用中,如何对这个集群进行操作呢? 我们利用ES系统,通常都是下面的架构: 在这里,客户端的请求通过LB进行负载均衡,因为操作任何一个ES的实例, ...

  8. Elasticsearch教程-从入门到精通(转载)

    转载,原文地址:http://mageedu.blog.51cto.com/4265610/1714522?utm_source=tuicool&utm_medium=referral 各位运 ...

  9. Elasticsearch简介与安装

    搜索 就是在任何场景下,找寻你想要的信息,这个时候,会输入一段你要搜索的关键字,然后就期望找到这个关键字相关的有些信息 垂直搜索 站内搜索 互联网搜索 电商网站,招聘网站,新闻网站,各种app IT系 ...

随机推荐

  1. [转]Oracle 分组聚合二种写法,listagg和wmsys.wm_concat

    本文转自:http://www.cnblogs.com/ycdx2001/p/3502495.html with temp as( select 'China' nation ,'Guangzhou' ...

  2. CF 371C-Hamburgers[二分答案]

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 有关数据库行、锁 的几个问题(rowlock)

    行锁的基本说明: SELECT au_lname FROM authors WITH (NOLOCK) 锁定提示                                 描述  HOLDLOC ...

  4. ipone5 无法安装ipa软件

    iphone5s软件无法安装解决方法一,点击设置 - 通用 - 访问限制,先关闭“安装应用程序”选项,再打开,把后台应用程序刷新也关了,测试. iphone5s软件无法安装解决方法二,点击设置 - 通 ...

  5. 如果觉得配置文件没有错,但web-dev-server总是报错,可以在hosts文件里加一行127.0.0.1 localhost

    如果觉得配置文件没有错,但web-dev-server总是报错,可以在hosts文件里加一行127.0.0.1 localhost

  6. 让Bootstrap轮播插件carousel支持左右滑动手势的三种方法

    因为最近开发的项目涉及到移动设备上的 HTML5 开发,其中需要实现轮播效果.然后最快捷的方式,你知道的(Bootstrap),然后原生的 Bootstrap 的 carousel.js 插件并没有支 ...

  7. SharePoint Foundation 2013 with SP1

    终于支持在 Windows Server 2012 R2 上安装了. 下载 另外,还有一个针对SharePoint Foundation 2013的重要更新.可以在安装SP1之前或之后安装. Micr ...

  8. Expression Blend4经验分享:文字公告无缝循环滚动效果

    这次分享一个类似新闻公告板的无缝循环滚动效果,相信很多项目都会应用到这个效果.之前我也百度了一下,网上的一些Silverlight的文字或图片滚动效果,都是一次性滚动的,如果要做到无缝循环滚动,多数要 ...

  9. 如何在Vue2中实现组件props双向绑定

    Vue学习笔记-3 前言 Vue 2.x相比较Vue 1.x而言,升级变化除了实现了Virtual-Dom以外,给使用者最大不适就是移除的组件的props的双向绑定功能. 以往在Vue1.x中利用pr ...

  10. 【有人@我】Android中高亮变色显示文本中的关键字

    应该是好久没有写有关技术类的文章了,前天还有人在群里问我,说群主很长时间没有分享干货了,今天分享一篇Android中TextView在大段的文字内容中如何让关键字高亮变色的文章 ,希望对大家有所帮助, ...