1、查看
方式:GET
URL:http://10.10.6.225:9200/?pretty

pretty
在任意的查询字符串中增加pretty参数。会让Elasticsearch美化输出JSON结果以便更加容易阅读

实测:
http://10.10.6.225:9200/?pretty

http://10.10.6.225:9200/
效果是一样的。

返回:
{
"name": "Uf8MPqK",
"cluster_name": "elasticsearch",
"cluster_uuid": "w_SOItRIQBGpZ4UuMTRlDg",
"version": {
"number": "6.2.1",
"build_hash": "7299dc3",
"build_date": "2018-02-07T19:34:26.990113Z",
"build_snapshot": false,
"lucene_version": "7.2.1",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}
2、计算集群中文档的数量,我们可以用这个:
方式:POST
URL:http://10.10.6.225:9200/_count?pretty
BODY:
{
"query": {
"match_all": {}
}
}
返回:
{
"count": 1505295,
"_shards": {
"total": 36,
"successful": 36,
"skipped": 0,
"failed": 0
}
}
3、简单查询
URL:http://10.10.6.225:9200/megacorp/employee/_search?q=last_name:Smith
方式:GET
返回:
{
"took": 53,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.2876821,
"hits": [
{
"_index": "megacorp",
"_type": "employee",
"_id": "2",
"_score": 0.2876821,
"_source": {
"first_name": "Jane",
"last_name": "Smith",
"age": 32,
"about": "I like to collect rock albums",
"interests": [
"music"
]
}
},
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"_score": 0.2876821,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
也可以使用查询表达式:
URL:http://10.10.6.225:9200/megacorp/employee/_search
方式:POST
BODY:
{
"query" : {
"match" : {
"last_name" : "Smith"
}
}
}
4、复杂搜索
目标:同样搜索姓氏为 Smith 的雇员,但这次我们只需要年龄大于 30 的。查询需要稍作调整,使用过滤器 filter ,它支持高效地执行一个结构化查询。
URL:http://10.10.6.225:9200/megacorp/employee/_search
方式:POST
BODY:
{
"query" : {
"bool": {
"must": {
"match" : {
"last_name" : "smith"
}
},
"filter": {
"range" : {
"age" : { "gt" : 30 }
}
}
}
}
}

5、添加mapping
方式:PUT
URL: http://10.10.6.225:9200/megacorp/_mapping/employee/
{
"properties": {
"interests": {
"type": "text",
"fielddata": true
}
}
}
或者:
方式:POST
URL:http://10.10.6.225:9200/megacorp/employee/
{
"mappings": {
"_doc": {
"properties": {
"interests": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
7、聚合
URL:http://10.10.6.225:9200/megacorp/employee/_search
方式:POST
{
"size":0,
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}

叫Smith的聚合
URL:http://10.10.6.225:9200/megacorp/employee/_search
方式:POST

{"size":0,
"query": {
"match": {
"last_name": "smith"
}
},
"aggs": {
"all_interests": {
"terms": {
"field": "interests"
}
}
}
}
聚合还支持分级汇总 。比如,查询特定兴趣爱好员工的平均年龄:
URL:http://10.10.6.225:9200/megacorp/employee/_search
方式:POST
{
"size":0,
"aggs" : {
"all_interests" : {
"terms" : { "field" : "interests" },
"aggs" : {
"avg_age" : {
"avg" : { "field" : "age" }
}
}
}
}
}

遗留问题:

1、http://10.10.6.225:9200/megacorp/employee/_search  格式是megacorp+employee二层,而我们的是一层:http://10.10.6.225:9200/t_resource_info/_search,这肯定是有问题的,需要明天仔细讨论下。

Elasticsearch: 权威指南---基础入门的更多相关文章

  1. Elasticsearch: 权威指南(官方教程)

    <Elasticsearch 权威指南>中文版 序言 前言 基础入门 深入搜索 处理人类语言 聚合 地理位置 数据建模 管理.监控和部署

  2. 初识Elastic search—附《Elasticsearch权威指南—官方guide的译文》

    本文作为Elastic search系列的开篇之作,简要介绍其简要历史.安装及基本概念和核心模块. 简史 Elastic search基于Lucene(信息检索引擎,ES里一个index—索引,一个索 ...

  3. Elasticsearch权威指南(中文版)

    Elasticsearch权威指南(中文版) 下载地址: https://pan.baidu.com/s/1bUGJmwS2Gp0B32xUyXxCIw 扫码下面二维码关注公众号回复100010 获取 ...

  4. Elasticsearch 权威指南

    Elasticsearch 权威指南 http://fuxiaopang.gitbooks.io/learnelasticsearch/content/index.html

  5. Elasticsearch 权威指南 NESTAPI地址

    Elasticsearch 权威指南:http://fuxiaopang.gitbooks.io/learnelasticsearch/content/index.html NEST:http://n ...

  6. elasticsearch权威指南

    elasticsearch权威指南 https://elasticsearch.cn/book/elasticsearch_definitive_guide_2.x/

  7. elasticsearch 权威指南入门阅读笔记(一)

    相关文档 esapi:https://es.xiaoleilu.com/010_Intro/10_Installing_ES.html     https://esdoc.bbossgroups.co ...

  8. ElasticSearch权威指南学习(结构化查询)

    请求体查询 简单查询语句(lite)是一种有效的命令行adhoc查询.但是,如果你想要善用搜索,你必须使用请求体查询(request body search)API. 空查询 我们以最简单的 sear ...

  9. Elasticsearch(一)基础入门

    介绍 Elasticsearch 是一个实时的分布式搜索分析引擎, 它能让你以前所未有的速度和规模,去探索你的数据. 它被用作全文检索.结构化搜索.分析以及这三个功能的组合: Elasticsearc ...

随机推荐

  1. mac go2shell 安裝

    配合Finder打开Finder,按住command键,拖动Go2Shell的图标到Finder菜单就可以在Finder快捷打开Go2Shell了

  2. C中有关引用和指针的异同

    参考于https://blog.csdn.net/wtzdedaima/article/details/78377201 C语言也学了蛮久的,其实一直都没有用到过或者碰到过引用的例子.前端时间再全面复 ...

  3. 题解【bzoj1503 [NOI2004]郁闷的出纳员】

    Description 给出一个下限 \(m\) ,要求维护以下操作 插入一个数(如果小于下限就不加) 给每个数加上一个数 给每个数减去一个数,并且删除掉 \(< m\) 的所有数 求目前第 \ ...

  4. __metaclass__ 实现单列模式

    class Singleton(type): """Singleton. @see: http://stackoverflow.com/questions/6760685 ...

  5. getContentLength() 指为 -1 的解决办法

    在这个坑里3个多小时啊.这里不得不抱怨下,国内的资料坑爹,全部copy不说,还是错的. 解决办法: 在服务端加入代码: File file = new File(path); //path为要下载的文 ...

  6. mq使用场景、不丢不重、时序性

    mq使用场景.不丢不重.时序性.削峰 参考: http://zhuanlan.51cto.com/art/201704/536407.htm http://zhuanlan.51cto.com/art ...

  7. Configure文件学习

    Linux安装软件有一种方式就是通过源码安装,源码通常是一个压缩包,打开压缩包,经常会看到一个叫configure的文件,而不见makefile文件.通常我们在自己的电脑写应用的时候都是通过makef ...

  8. zlib打印bit length overflow

    bit length overflow code bits -> code bits -> zlib库输出此log,此log不代表压缩出现错误,没有什么危害,而且zlib非常稳定,完全可以 ...

  9. 【BZOJ】4559: [JLoi2016]成绩比较 计数DP+排列组合+拉格朗日插值

    [题意]n位同学(其中一位是B神),m门必修课,每门必修课的分数是[1,Ui].B神碾压了k位同学(所有课分数<=B神),且第x门课有rx-1位同学的分数高于B神,求满足条件的分数情况数.当有一 ...

  10. Linux服务-搭建NFS

    任务目标:二进制安装nfs,作为共享存储挂载在三台web的网站根目录下,在任意一台web上修改的结果,其余两台都可以看到 首先来安装NFS服务,NFS顾名思义,就是极品飞车,哦不!是网络文件服务的意思 ...