ElasticSearch高级查询
ElasticSearch高级查询
https://www.imooc.com/video/15759/0 ElasticSearch查询 1,子条件查询:特定字段查询所指特定值 1.1query context,有_score
1.1.1全文本查询,针对文本类型数据
1.1.1.1 模糊匹配
POST http://127.0.0.1/book/_search
{
"query":{
"match":{
"author":"瓦力"
}
}
}
{
"query":{
"match":{
"title":"ElasticSearch入门"
}
}
} 1.1.1.2 习语匹配
{
"query":{
"match_phrase":{
"title":"ElasticSearch入门"
}
}
} 1.1.1.3 多字段匹配
{
"query":{
"multi_match":{
"query":"瓦力",
"fields":["author","title"]
}
}
} 1.1.1.4 语法查询
{
"query":{
"query_string":{
"query":"ElasticSearch AND 大法"
}
}
} {
"query":{
"query_string":{
"query":"(ElasticSearch AND 大法) OR Python"
}
}
} {
"query":{
"query_string":{
"query":"瓦力 OR ElasticSearch",
"fields":["title","author"]
}
}
}
1.1.2字段级别查询,针对结构化数据,如数字、日期等 {
"query":{
"term":{
"word_count":1000
}
}
} {
"query":{
"term":{
"author":"瓦力"
}
}
}
{
"query":{
"range":{
"word_count":{
"gte":1000,
"lte":2000
}
}
}
}
{
"query":{
"range":{
"word_count":{
"gt":1000,
"lte":2000
}
}
}
}
{
"query":{
"range":{
"publish_date":{
"gte":"2017-01-01",
"lte":"2017-12-31"
}
}
}
}
{
"query":{
"range":{
"publish_date":{
"gte":"2017-01-01",
"lte":"now"
}
}
}
}
1.2filter context
filter表示查找是不是 {
"query": {
"bool": {
"filter": {
"term": {
"word_count": 1000
}
}
}
}
} 2,复合条件查询:以一定的逻辑组合子条件查询 2.1 固定分数查询
{
"query": {
"match": {
"title": "ElasticSearch"
}
}
} {
"query": {
"constant_score": {
"filter": {
"match": {
"title": "ElasticSearch"
}
}
}
}
} {
"query": {
"constant_score": {
"filter": {
"match": {
"title": "ElasticSearch"
}
},
"boost": 2
}
}
} 2.2 bool查询 should - 表示 或者
{
"query": {
"bool": {
"should": [
{
"match":{
"author": "瓦力"
}
},
{
"match": {
"title": "ElasticSearch"
} } ]
}
}
} must - 表示 必须 {
"query": {
"bool": {
"must": [
{
"match":{
"author": "瓦力"
}
},
{
"match": {
"title": "ElasticSearch"
} } ]
}
}
} {
"query": {
"bool": {
"must": [
{
"match":{
"author": "瓦力"
}
},
{
"match": {
"title": "ElasticSearch"
} } ],
"filter": [
{
"term": {
"word_count": 1000
}
}
]
}
}
}
{
"query": {
"bool": {
"must_not": {
"term": {
"author": "瓦力"
}
}
}
}
}
https://www.imooc.com/video/15759/0
ElasticSearch查询
1,子条件查询:特定字段查询所指特定值
1.1query context,有_score1.1.1全文本查询,针对文本类型数据1.1.1.1 模糊匹配POST http://127.0.0.1/book/_search{ "query":{ "match":{ "author":"瓦力" } }}{ "query":{ "match":{ "title":"ElasticSearch入门" } }}
1.1.1.2 习语匹配{ "query":{ "match_phrase":{ "title":"ElasticSearch入门" } }}
1.1.1.3 多字段匹配{ "query":{ "multi_match":{ "query":"瓦力", "fields":["author","title"] } }}
1.1.1.4 语法查询{ "query":{ "query_string":{ "query":"ElasticSearch AND 大法" } }}
{ "query":{ "query_string":{ "query":"(ElasticSearch AND 大法) OR Python" } }}
{ "query":{ "query_string":{ "query":"瓦力 OR ElasticSearch", "fields":["title","author"] } }}1.1.2字段级别查询,针对结构化数据,如数字、日期等
{ "query":{ "term":{ "word_count":1000 } }}
{ "query":{ "term":{ "author":"瓦力" } }}{ "query":{ "range":{ "word_count":{ "gte":1000, "lte":2000 } } }}{ "query":{ "range":{ "word_count":{ "gt":1000, "lte":2000 } } }}{ "query":{ "range":{ "publish_date":{ "gte":"2017-01-01", "lte":"2017-12-31" } } }}{ "query":{ "range":{ "publish_date":{ "gte":"2017-01-01", "lte":"now" } } }}1.2filter contextfilter表示查找是不是
{"query": {"bool": {"filter": {"term": {"word_count": 1000}}}}}
2,复合条件查询:以一定的逻辑组合子条件查询
2.1 固定分数查询{"query": {"match": {"title": "ElasticSearch"}}}
{"query": {"constant_score": {"filter": {"match": {"title": "ElasticSearch"}}}}}
{"query": {"constant_score": {"filter": {"match": {"title": "ElasticSearch"}},"boost": 2}}}
2.2 bool查询
should - 表示 或者{"query": {"bool": { "should": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}]}}}
must - 表示 必须
{"query": {"bool": { "must": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}]}}}
{"query": {"bool": { "must": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}],"filter": [{"term": {"word_count": 1000}}]}}}{"query": {"bool": { "must_not": {"term": {"author": "瓦力"}}}}}
ElasticSearch高级查询的更多相关文章
- elasticsearch 高级查询
高级查询 子条件查询 (特定字段查询所指特定值) 复合条件查询 (以一定的逻辑组合子条件查询) 一.子条件查询 子条件查询分为 query context.filter context 1.query ...
- 031 Spring Data Elasticsearch学习笔记---重点掌握第5节高级查询和第6节聚合部分
Elasticsearch提供的Java客户端有一些不太方便的地方: 很多地方需要拼接Json字符串,在java中拼接字符串有多恐怖你应该懂的 需要自己把对象序列化为json存储 查询到结果也需要自己 ...
- java整合Elasticsearch,实现crud以及高级查询的分页,范围,排序功能,泰文分词器的使用,分组,最大,最小,平均值,以及自动补全功能
//为index创建mapping,index相当于mysql的数据库,数据库里的表也要给各个字段创建类型,所以index也要给字段事先设置好类型: 使用postMan或者其他工具创建:(此处我使用p ...
- Elasticsearch 数据查询
数据准备: PUT /shop { "settings": { "number_of_shards": 3, "number_of_replicas& ...
- 测试使用索引库crud和高级查询分页
1.搭建ES的服务 导入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifa ...
- MongoDB高级查询详细
前言 前几篇,老玩家绕道即可,新手晚上闲着也是蛋疼,不如把命令敲一边,这样你就会对MongoDB有一定的掌握啦.如果没有安装MongoDB去看我的上一篇博客 MongoDB下载安装与简单增删改查 前 ...
- T-SQL高级查询语句
高级查询 1.连接查询,对结果集列的扩展select * from info select * from info,nation #形成笛卡尔积select * from info,nation wh ...
- SQL Server高级查询
简介 关于数据库,我们经常会听说"增查删改"之类的词语,听起来很简单,但是如果想要准确的获取到需要的数据的话,还是要花点功夫的.下面由我来和大家谈谈高级查询的用法以及和普通查询的区 ...
- mongodb高级查询
前几篇,老玩家绕道即可,新手晚上闲着也是蛋疼,不如把命令敲一边,这样你就会对MongoDB有一定的掌握啦.如果没有安装MongoDB去看我的上一篇博客 MongoDB下载安装与简单增删改查 前奏:启 ...
随机推荐
- Codeforces Round #357 (Div. 2) A
A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- js实时监听input中值得变化
<!DOCTYPE html> <html> <head> <title>zepto</title> <meta name=" ...
- UVA10154 Weights and Measures
https://vjudge.net/problem/UVA-10154 ↑Vjudge大法好 堆一个乌龟塔.每只乌龟有重量w和承重能力s(也要承受自己的重量,所以实际可托起s-w),问最多能堆几只乌 ...
- 百度之星初赛(A)——T1
小C的倍数问题 Problem Description 根据小学数学的知识,我们知道一个正整数x是3的倍数的条件是x每一位加起来的和是3的倍数.反之,如果一个数每一位加起来是3的倍数,则这个数肯定是3 ...
- 原生dialog
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- pdf.js如何跨域读取pdf文件?
今天,上线一个客户网站之后(使用的是广州新一代虚拟空间)发现在读取上传的pdf文件的时候读取错误,通过直接在浏览器输入文件地址的时候发现文件地址被重定向了(呵呵!),结果就是pdf文件源由本地直接变成 ...
- 生成DLL
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- [LeetCode] Combinations 回溯
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...
- SQL联合查询(内联、左联、右联、全联)语法
SQL联合查询(内联.左联.右联.全联)语法 概述: 联合查询效率较高,举例子来说明联合查询:内联inner join .左联left outer join .右联right outer join ...
- VC++中有关句柄和指针及其转换(转)
原文转自 https://blog.csdn.net/jearmy/article/details/47030011 1.MFC窗口的句柄和指针的转换 (1) 一般窗口对象都会有一个其对应的句柄变量, ...