ElasticSearch 7.X系列三:URI查询
常用参数
q---查询字符串
sort---排序执行。可以是fieldName或 fieldName:asc/ 的形式fieldName:desc。fieldName可以是文档中的实际字段,也可以是特殊_score名称,表示基于分数的排序。可以有几个sort参数(顺序很重要)。
from---从命中的索引开始返回。默认为0。
size---要返回的点击次数。默认为10。
_source_include---查询包含某些source字段的文档。
_source_exclude---查询不包含某些source字段的文档。
timeout---搜索超时,将搜索请求限制在指定的时间值内执行,并使用在到期时累积的点击数进行保释。默认为无超时。
default_field---默认为index.query.default_field,即未指定字段前缀时返回所有字段,索引设置为*
default_operator---默认查询运算符,未指定时默认为OR。
analyzer---用于分析查询字符串的分析器名称。
_source---设置为false禁用_source字段检索。
analyze_wildcard---是否应分析通配符和前缀查询,默认为false
status:active---where the status field contains active
---(status相当于fieldname,active相当于值----->TESTID:39232032303039,由于=被用在了前面“q=”,所以这里用“:”代替了“=”)
title:(quick OR brown)---where the title field contains quick or brown. If you omit the OR operator the default operator will be used
author:"John Smith"---where the author field contains the exact phrase "john smith"
_exists_:title---where the field title has any non-null value
date:[2012-01-01 TO 2012-12-31]---All days in 2012
count:[10 TO *]---Numbers from 10 upwards
count:>=10---Numbers from 10 upwards
#查询所有的属性中只要包含2012的所有的数据,泛查询 :
GET movies/_search?q=2012
#查询title中包含2012的所有的电影,df(default field)
GET movies/ search?q=2012&df=title
或者
GET movies/ search?q=title:2012
#查询title中包含2012,从第10条开始,查询8条 数据
GET movies/_search?q=title:2012&from=10&size=8
#查询title中包含Beautiful或者Mind的所有的数据
GET movies/_search?q=title:Beautiful Mind
GET movies/_search?q=title:(Beautiful Mind)
GET movies/_search?q=title:(+Beautiful +Mind)
#查询title中包含 "Beautiful Mind"这个短语的所 有的数据
GET movies/_search?q=title:"Beautiful Mind"
#查询title中既包含Mind又包含Beautiful的所有 的数据,与顺序没有关系
GET movies/_search?q=title:(Mind AND Beautiful)
#查询title中包含Beautiful但是不包含mind的所 有的数据
GET movies/_search?q=title:(Beautiful NOT Mind)
GET movies/_search?q=title:(Beautiful -Mind)
#查询title中包含Beautiful且电影上映时间 在2012年之后的所有的数据
GET movies/_search?q=title:Beautiful AND year:>=2012
#查询2018年之后上映的电影
GET movies/_search?q=year:>=2018
#查询在2012到2017年上映的电影
GET movies/_search?q=year:(>=2012 AND <2018)
#查询2016年到2017年上映的电影,必须以 ] 结尾
GET movies/_search?q=year:{2015 TO 2017]
# ?代表一个字母 GET movies/_search?q=title:Min* # 查询title中包含以 Min开头的字母的电影
GET movies/_search?q=title:Min?x