查询所有的索引
GET /_cat/indices
查询索引下的所有数据(类似全表扫描)
GET /index/_search
GET /pos-kzy/_search
查询固定条数数据
GET /pos-kzy/_search
{
"from": 0,
"size": 2
}
简单的条件查询
GET /pos-kzy/_search?q=bind:"YES"
复杂条件查询query
GET /pos-kzy/_search
{
"query": {
"term": {
"bind": {
"value": "YES"
}
}
}
}
GET /pos-kzy/_search
{
"query": {
"match": {
"bind": "YES"
}
}
}
term和match的区别
复杂查询多条件(and)
GET /pos-kzy/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"bind": {
"value": "YES"
}
}
},
{
"term": {
"active": {
"value": "YES"
}
}
}
]
}
}
}
多条件复杂查询(or)
GET /pos-kzy/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"bind": {
"value": "YES"
}
}
}
],
"should": [
{
"term": {
"active": {
"value": "YES"
}
}
}
]
}
}
}
多条件复杂查询(过滤)
GET /pos-kzy/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"bind": {
"value": "YES"
}
}
}
],
"should": [
{
"term": {
"active": {
"value": "YES"
}
}
}
],
"filter": [
{
"range": {
"posPlanId": {
"gte": 1,
"lte": 1
}
}
}
]
}
}
}
排序
GET /pos-kzy/_search
{
"sort": [
{
"posBindTime": {
"order": "desc"
}
}
]
}
查询指定的字段
GET /pos-kzy/_search
{
"query": {
"match_all": {}
}
, "_source": ["agencyId", "agencyName"]
}