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. Flex学习笔记PopUpMenuButton

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  2. leetcode990

    class Finder: def __init__(self): self.Parent = [i for i in range(26)] def union(self, p, q): self.P ...

  3. Linux定时任务 结合PHP实现实时监控

    首先说说cron,它是一个linux下的定时执行工具.根用户以外的用户可以使用 crontab 工具来配置 cron 任务. 所有用户定义的 crontab 都被保存在/var/spool/cron ...

  4. <基础> PHP 进阶之 类型转换

    引用官方的解释 PHP 在变量定义中不需要(或不支持)明确的类型定义:变量类型是根据使用该变量的上下文所决定的.也就是说,如果把一个 string 值赋给变量$var,$var 就成了一个 strin ...

  5. 使用expect解决shell交互问题

    比如ssh的时候,如果没设置免密登陆,那么就需要输入密码.使用expect可以做成自动应答 1.expect检测和安装 sudo apt-get install tcl tk expect 2.脚本样 ...

  6. UI5-学习篇-15-云连接SAP Cloud Connector

    请关注地址:http://blog.itpub.net/29829936/viewspace-2128829/ 1.SCC下载及安装 https://tools.hana.ondemand.com/# ...

  7. bash: export: “path” not a valid identifier [closed]

    export SPARK_HOME=/usr/local/spark export PATH=$PATH:$SPARK_HOME/bin bash: export: “path” not a vali ...

  8. 应用SharedPreference保存程序的配置信息

    SharedPreference: 1.用来保存应用程序的配置信息的XML文件,内部的数据形式为键值对 2.一般存在于/data/data/<包名>shared_prefs目录下 3.该对 ...

  9. es6 初级之---const 和 默认参数

    1. const 的定义: 1.1 常量定义的时候要赋值,不赋值是会报错的: <!DOCTYPE html> <html lang="en"> <he ...

  10. Reduction: the word AT

    Reduction: the word AT Share Tweet Share Tagged With: AT Reduction Study the AT reduction.  There ar ...