eelastic search主要有两种查询方式,一种是查询字符串,一种是请求体(json格式)查询。

查询字符串:

查询字符串的功能相对简单,使用容易。

比如GET http://localhost:9200/list/doc/_search,直接在游览器地址栏输入以上地址,elastic search会返回json格式字符串,意思是查询所有list索引下面类型为doc的文档。

那如果我是 GET http://localhost:9200/_search呢?没错就是在查询所有索引所有类型中的文档,值得一提的是elastic search 将在7以后版本取消类型(type)这一概念。

现在假如我有这样格式的文档(导入bank索引详细见我关于logstash导入elastic search的博客)

{
"_index": "bank",
"_type": "account",
"_id": "25",
"_version": 1,
"_score": 1,
"_source": {
"account_number": 25,
"balance": 40540,
"firstname": "Virginia",
"lastname": "Ayala",
"age": 39,
"gender": "F",
"address": "171 Putnam Avenue",
"employer": "Filodyne",
"email": "virginiaayala@filodyne.com",
"city": "Nicholson",
"state": "PA"
}
}

我想查找 firstname下面名为Virginia的所有账户,那么可以使用如下查询字符串

GET http://localhost:9200/bank/account/_search?q=firstname:Virginia

返回结果

{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 4.882802,
"hits": [
{
"_index": "bank",
"_type": "account",
"_id": "25",
"_score": 4.882802,
"_source": {
"account_number": 25,
"balance": 40540,
"firstname": "Virginia",
"lastname": "Ayala",
"age": 39,
"gender": "F",
"address": "171 Putnam Avenue",
"employer": "Filodyne",
"email": "virginiaayala@filodyne.com",
"city": "Nicholson",
"state": "PA"
}
}
]
}
}
如果我想找firstname为Virginia,lastname为Ayala的人,可以用如下查询字符串
GET http://localhost:9200/bank/account/_search?q=firstname:Virginia+lastname:Ayala
 
如果我们想要一些更加复杂的查询,那么就要采用请求体查询了
比如 GET http://localhost:9200/bank/account/_search?q=firstname:Virginia+lastname:Ayala
在请求体查询中是这样的

GET /bank/account/_search
{
"query": {
"bool": {
"must":[
{ "match": { "firstname": "Virginia" }},
{ "match": { "lastname": "Ayala" }}
]
}
}
}

 
 

elastic search 查询的更多相关文章

  1. elastic search查询命令集合

    Technorati 标签: elastic search,query,commands 基本查询:最简单的查询方式 query:{"term":{"title" ...

  2. elastic search 查询语句

    部署了半个月,分析一下数据: 需要提前知道的是,tpot中,每天的数据存一个index,然后每个index里面有不同的type,每条请求一个document 共24万条请求: 查看整个集群所有数据 以 ...

  3. 分库分表后跨分片查询与Elastic Search

    携程酒店订单Elastic Search实战:http://www.lvesu.com/blog/main/cms-610.html 为什么分库分表后不建议跨分片查询:https://www.jian ...

  4. Elastic Search操作入门

    前言 Elastic Search是基于Lucene这个非常成熟的索引方案,另加上一些分布式的实现:集群,sharding,replication等.具体可以参考我同事写的文章. 本文主要介绍ES入门 ...

  5. tpot从elastic search拉攻击数据之一 找本地数据端口

    前面,我们已经在ubuntu服务器上部署好了tpot,并启动进行数据捕获 可以通过64297端口登陆到kibana可视化平台查看捕获到攻击的情况. 现在要拉取攻击数据了,但是该怎么拉呢? 看了一上午的 ...

  6. java连接elastic search 9300

    java连接elastic search 导入jar包:https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/_maven ...

  7. elastic search使用

    elastic使用 使用python时注意保持一个好习惯:不要使用类似str.type这样的变量名,很容易引发错误: https://blog.csdn.net/lifelegendc/article ...

  8. elastic search远程测试

    elastic search远程测试 推荐:elastic官方教程:https://www.elastic.co/guide/en/elasticsearch/reference/6.2/index. ...

  9. 深入分析Elastic Search的写入过程

    摘要 之前写过一篇ElasticSearch初识之吐槽,不知觉竟然过去了两年了.哎,时光催人老啊.最近又用到了ES,想找找过去的总结文档,居然只有一篇,搞了半年的ES,遇到那么多的问题,产出只有这么点 ...

随机推荐

  1. uva-10763-交换生

    题意:有一个交换生由A->B,想交换得有一个B->A,问,是不是所有人都能交换成. 俩个数字交换偶数次还是自身,开一个数组mark,模拟完所有样例后,看数组是不是还是初始化数组. #inc ...

  2. Windows下python库的常用安装方法

    目录:       1.pip安装(需要pip)       2.通过下载whl文件安装(需要pip)       3.在pythn官网下载安装包安装(不需要pip)   方法一:pip安装. 这是最 ...

  3. java.sql.SQLException: com.mysql.jdbc.Driver

    项目本来是 oracle 驱动 + druid 数据源配置,现在要修改为 mysql+druid数据源配置 启动项目的时候报:java.sql.SQLException: com.mysql.jdbc ...

  4. Maven下载私服上的jar包

    1.配置M2_HOME/conf/settions.xml <server> <id>maven-public</id> <username>admin ...

  5. 3. java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0

    问题描述:

  6. 数电——全减器分析(用74HC138设计提示)

    -1=1(即Di=1). Di=(Y1' * Y2' * Y4' * Y7')'可以得到74HC138来表示,(注意:Ai,Bi,Ci-1的各自位权对应A2,A1,A0) Ci同理可得.

  7. 使用子查询创建表(oracle)

    转自:https://blog.csdn.net/lxh123456789asd/article/details/81164321 语句: CREATE TABLE tablename[(column ...

  8. [转]使用Ubuntu Live CD修复Grub引导教程

    这个教程的方法我用过了,能够解决了我的问题. 这篇文章主要介绍了使用Ubuntu Live CD修复Grub引导教程,本文以 Ubuntu Live CD 修复 Grub 引导为例,需要的朋友可以参考 ...

  9. golang:send mail using smtp package

    go语言发送邮件,可以使用smtp包,两个关键函数: func PlainAuth(identity, username, password, host string) Auth func SendM ...

  10. 小柒2012 / spring-boot-quartz

    spring-boot-quartz 基于spring-boot+quartz的CRUD动态任务管理系统,适用于中小项目. 基于spring-boot 2.x +quartz 的CRUD任务管理系统: ...