例如
curl -X GET "localhost:9200/twitter/_search?q=user:kimchy&pretty"
q指定查询语句,使用Query String Syntax
df默认字段,不指定时,会对所有字段进行查询
profile显示查询如何执行的
analyzer 指定分析器
参数说明可在下面链接中查看
https://www.elastic.co/guide/en/elasticsearch/reference/7.0/search-uri-request.html
movies数据导入请看:
es+kibana+logstash快速安装上手
查询title字段包含2012的结果,不加df的话,会对所有字段进行查询q=2012&df=title也等价于q=title:2012
GET /movies/_search?q=2012&df=title
{
"profile": "true"
}
在profile
"profile" : {
"shards" : [
{
"id" : "[Ko-M9qn6S_eVTQodS2IElA][movies][0]",
"searches" : [
{
"query" : [
{
"type" : "TermQuery",
"description" : "title:2012",
"time_in_nanos" : 1664736,
分组
GET /movies/_search?q=title:(2012 2013)
{
"profile": "true"
}
"profile" : {
"shards" : [
{
"id" : "[Ko-M9qn6S_eVTQodS2IElA][movies][0]",
"searches" : [
{
"query" : [
{
"type" : "BooleanQuery",
"description" : "title:2012 title:2013", # 查询title为2012,或者2013
布尔操作
AND OR NOT 或者 && // !
注意,必须大写
AND
GET /movies/_search?q=title:(beautiful AND mind)
{
"profile": "true"
}
"query" : [
{
"type" : "BooleanQuery",
"description" : "+title:beautiful +title:mind",
NOT
GET /movies/_search?q=title:(beautiful not mind)
{
"profile": "true"
}
"query" : [
{
"type" : "BooleanQuery",
"description" : "title:beautiful title:not title:mind",
范围查询
- 区间表示:
- year:[* TO 2018]
GET /movies/_search?q=year: [* TO 2018]
算数符号
- year: > 2010
- year:(>=2010 AND <2019)
GET /movies/_search?q=year: (>=2010 AND <2019)
通配符查询
通配符查询效率低,占用内存大,不建议使用
- ?代表一个字符,* 代表0或多个字符
- title: mi?d
- title: be*
GET /movies/_search?q=title:(Grumpier Old M?>)