Should
GET /test/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"cf3.c42.c4.keyword": "1000000000"
}
},
{
"term": {
"cf3.d1.c4.keyword": {
"value": "1000000001"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"cf3.c42.c4.keyword": "1000000001"
}
},
{
"term": {
"cf3.d1.c4.keyword": {
"value": "1000000000"
}
}
}
]
}
}
]
}
}
}
filter
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"cf1.keyword": {
"value": "0000000001"
}
}
}
],
"filter": [
{
"range": {
"cf3.c26.keyword": {
"gte": 34.78,
"lte": 50
}
}
},
{
"range": {
"cf3.c27.keyword": {
"gte": 116.65,
"lte": 150
}
}
}
]
}
}
A and (B or C)写法如下:
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"cf8": {
"value": "reg8"
}
}
},
{
"bool": {
"should": [
{
"term": {
"cf1.keyword": {
"value": "0000000000"
}
}
},
{
"term": {
"cf1.keyword": {
"value": "0000000001"
}
}
}
]
}
}
]
}
},
"size": 100
}
(A and B) or (C and D)写法如下:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match_phrase": {
"A": "你好"
}
},
{
"match_phrase": {
"B": "头"
}
}
]
}
},
{
"bool": {
"must": [
{
"match_phrase": {
"C": "美国"
}
},
{
"match_phrase": {
"D": "世界"
}
}
]
}
}
]
}
},
"size": 100
}
_all与term同时使用:
查询同时,通过filter条件在不影响打分的情况下筛选出想要的数据
简单的filter查询
实例1:先查询index为library,type为books的全部文档;再过滤price等于20的
分词查询,然后精确搜索
GET /test/_search
{
"query":{
"match":{
"_all":"XXX"
}
},
"post_filter":{
"term":{
"person.age":"20"
}
}
}
另一种写法:
GET /test/_search
{
"query":{
"bool":{
"must":[
"match":{
"_all":"XXX"
}
],
"filter":{
"bool":{
"must":[
{
"term":{
"person.name":"jack"
}
},
{
"term":{
"person.age":"27"
}
}
]
}
}
}
}
}
分词查询,然后模糊搜索,使用match_phrase可以对输入的搜索语句进行分词
GET /test/_search
{
"query":{
"match":{
"_all":"XXX"
}
},
"post_filter":{
"wildcard":{
"person.name":"*<>*"
}
}
}
判断查询某个字段存在
GET test/_search
{
"query": {
"exists":{
"field": "person.name"
}
}
}
range(a,b) AND (C Or D)
{
"size": 0,
"query": {
"bool": {
"must": [
"bool": {
"should": [
"term": {
"A": {
"value": "001"
}
},
"term": {
"B": {
"value": "002"
}
}
]
},
"range": {
"start_time": {
"from": "C",
"to": "D"
}
}
]
}
}
}