2、REST Request Body
1)查询设置
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '{
query: {match_all: {}},
size: 5,
from: 0,
sort: {balance: {order: "desc"}},
_source: ["balance", "account_number"]
'
query:设置查询条件
size:返回的数据量
from:数据从哪条开始,第一条是0
sort:排序
_source:返回哪些字段
2)查询条件
- match query
match_all:所有数据
match:等于或包含某些值的
match_phrase:等于或包含某个值
查询所有数据
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '{query: {match_all: {}}}'
查询account_number(数值类型)是20的数据
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {match: {account_number: 20}}
}'
查询address包含mill的数据
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {match: {address: "mill"}}
}'
查询address包含mill或lane的数据
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {match: {address: "mill lane"}}
}'
查询address包含"mill lane"的数据,文本作为一个整体进行比较
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {match_phrase: {address: "mill lane"}}
}'
- boolean query
must:相当于and操作
should:相当于or操作
must_not:相当于非操作
address包含mill并且包含lane
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {bool: {must: [{match: {address: "mill"}}, {match: {address: "lane"}}]}}
}'
address包含mill或包含lane
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {bool: {should: [{match: {address: "mill"}}, {match: {address: "lane"}}]}}
}'
address不包含mill并且不包含lane
curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
{
query: {bool: {must_not: [{match: {address: "mill"}}, {match: {address: "lane"}}]}}
}'
多个条件组合
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}'
filter query
aggregation query