• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > Elasticsearch的简单使用案例

Elasticsearch的简单使用案例

作者:黎杰 字体:[增加 减小] 来源:互联网

本文主要包含elasticsearch等服务器相关知识,黎杰希望可以进行参考
  • 1.添加一个学生的成绩(ip: port/库/表/id)
curl -XPUT 'http://192.168.80.123:9200/school/jsj/1' -d '{
  "class": "软件工程",
  "subject": "math",
  "name": {
    "first": "li",
    "last": "jie"
  },
  "create_time": "2017-08-10",
  "score": "98"
}'
  • 2.通过浏览器用id查询学生成绩
http://192.168.80.123:9200/school/jsj/1

结果:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "class": "软件工程",
    "subject": "math",
    "name": {
      "first": "li",
      "last": "jie"
    },
    "create_time": "2017-08-10",
    "score": "98"
  }
}
  • 3.在linux中通过curl的方式用id查询学生成绩
curl -XGET 'http://192.168.80.123:9200/school/jsj/1'

返回:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "class": "软件工程",
    "subject": "math",
    "name": {
      "first": "li",
      "last": "jie"
    },
    "create_time": "2017-08-10",
    "score": "98"
  }
}
  • 4.添加另外一个学生的成绩
curl -XPUT 'http://192.168.80.123:9200/school/jsj/2' -d '{
  "subject": "math",
  "name": {
    "first": "zhang",
    "last": "san"
  },
  "create_time": "2017-07-01",
  "score": "59"
}'
  • 5.通过_source获取指定的字段
curl -XGET 'http://192.168.80.123:9200/school/jsj/1?_source=subject'

结果:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "subject": "math"
  }
}
curl -XGET 'http://192.168.80.123:9200/school/jsj/1?_source=subject,score'

结果:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "score": "98",
    "subject": "math"
  }
}
curl -XGET 'http://192.168.80.123:9200/school/jsj/1?_source'

结果:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "class": "软件工程",
    "subject": "math",
    "name": {
      "first": "li",
      "last": "jie"
    },
    "create_time": "2017-08-10",
    "score": "98"
  }
}
  • 6.可以通过覆盖的方式更新
curl -XPUT 'http://192.168.80.123:9200/school/jsj/1' -d '{
  "subject": "math",
  "name": {
    "first": "li",
    "last": "jie"
  },
  "create_time": "2017-08-11",
  "score": "100"
}'

返回:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 2,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "created": false
}

再查看就变成100分了.

  • 7.通过_updateAPI的方式单独更新你想要更新的
curl -XPOST 'http://192.168.80.123:9200/school/jsj/1/_update' -d '{
  "doc": {
    "score": "666"
  }
}'

返回:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 4,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  }
}

再查看就变成666分了.

  • 8.删除一个文档
curl -XDELETE 'http://192.168.80.123:9200/school/jsj/1'

返回:

{
  "found": true,
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "_version": 5,
  "result": "deleted",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  }
}

再查看id为1的返回数据为:

{
  "_index": "school",
  "_type": "jsj",
  "_id": "1",
  "found": false
}
  • 9.查询所有
curl -XGET 'http://192.168.80.123:9200/school/jsj/_search' -d '{  
    "query": { "match_all": {} }  
}'

返回:

{
    "took": 10,                //执行搜索的时间(以毫秒为单位)
    "timed_out": false,        //是否超时
    "_shards": {               //搜索分片,成功和失败的分片
    "total": 5,                //总搜索分片
    "successful": 5,           //成功搜索分片
    "failed": 0                //失败搜索分片 
    },
    "hits": {
        "total": 2,               //符合我们的搜索条件的文档总数
        "max_score": 1.0,         //最高分数
        "hits": [{                //搜索结果的实际数组(默认为前10个文档)
            "_index": "school",
            "_type": "jsj",
            "_id": "2",
            "_score": 1.0,           //是文档的分数信息,与排名相关度有关,参考各大搜索引擎的搜索结果,就容易理解。
            "_source": {
                "subject": "math",
                "name": {
                    "first": "zhang",
                    "last": "san"
                },
                "create_time": "2017-07-01",
                "score": "59"
            }
        },
        {
        "_index": "school",
        "_type": "jsj",
        "_id": "1",
        "_score": 1.0,            //是文档的分数信息,与排名相关度有关,参考各大搜索引擎的搜索结果,就容易理解。
        &quo
  


 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • 【甘道夫】Spark1.3.0 Submitting Applications 官方文档精华摘要,spark1.3
  • apache hadoop-2.6.0-CDH5.4.1 安装笔记,hadoop2.6.0安装
  • UcloudClient,icloud
  • 云服务器之间实时文件同步和文件备份的最简单高效的免费方案,实时文件备份
  • [Spark源码剖析] DAGScheduler提交stage,sparkdagscheduler
  • RedHadoop创始人童小军在北京开讲“Hadoop2.0集群优化与管理”啦!,redhadoophadoop2.0
  • HBase扫描器与过滤器,HBase扫描器过滤器
  • 从Hadoop URL中读取数据,hadoopurl读取数据
  • 通过iscsi协议使用ceph rbd,iscsi协议cephrbd
  • openstack-计算节点安装(Node),openstack-node

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • 【hadoop】 3002-mapreduce程序统计单词个数示例,hadoopmapreduce
    • @RequestMapping的params参数 @RequestMapping(params = "method=save"),requestmapping
    • Navicat连接oracle,出现Only compatible with oci version 8.1 and&nb,navicatoci
    • libvirt 部分API 介绍,libvirtapi
    • 什么是Code Review,CodeReview
    • CloudStack VM运行状态的监控-Management,cloudstack系统vm
    • 万法归宗之Hadoop编程无界限,万法归宗hadoop
    • spark core源码分析14 参数配置,sparkcore
    • 如何解决Greenplum master node与seg node元数据不一致,greenplumseg
    • 《转》OpenStack Live Migration,《转》openstack

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有