结构化查询就是对结构比较精确的值的查询,es中对bool、数字、date的查询都是结构化查询。包括term查询、range查询
PUT struct_query_index/_bulk
{"index":{"_id":1}}
{"price":10,"available":true,"productDate":"2010-10-10","productId":"PK-45TKY-90"}
{"index":{"_id":2}}
{"price":19,"available":true,"productDate":"2010-10-10","productId":"PK-45TKY-KK"}
{"index":{"_id":3}}
{"price":20,"available":true,"productDate":"2010-10-10","productId":"PK-45TKY-343"}
{"index":{"_id":4}}
{"price":10,"available":false,"productDate":"2010-10-10","productId":"PK-45TKY"}
1, term查询
GET struct_query_index/_search
{
"query": {
"term": {
"available": {
"value": "true"
}
}
}
}
2, constant_score 不算分term查询
// constant_score
GET struct_query_index/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"available": {
"value": "true"
}
}
},
"boost": 1.2
}
}
}
3, constant_score 不算分range查询
GET struct_query_index/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte": 10,
"lte": 17
}
}
},
"boost": 1.2
}
}
}
4, constant_score 不算分date类型的range查询
GET struct_query_index/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"productDate": {
"gte": "now-2y"
}
}
},
"boost": 1.2
}
}
}