我有两个实体,例如“用户和活动”。活动包含归档的ageGroup,例如[“ 10:20”,“ 25:30”]和用户实体包含的年龄字段。考虑到用户年龄为26岁,因此他/她有资格参加该活动。 我想获取所有满足上述条件的活动
GET _search
{
"query": {
"bool": {
"filter": {
"range": {
"ageGroup": {
"gte": 50,
"lte": 55
}
},
"term": {"****": "M"}
},
"must": [
{
"term": {"******": {"value": "15"}}
}
] ,"should": [
{
"match": {"******": "7"}
},
{
"match": {"******": "1"}
}
]
}
}
}
答案 0 :(得分:0)
包含(实体/对象)包含列表
public class Include {
@Field(type= FieldType.Nested)
private List<AgeGroup> age;
}
数据: {.....,include.age:{“ id”:4,“ minAge”:4,4,“ maxAge”:9},{“ id”:3,“ minAge”:1,“ maxAge”:4} ,.....}
DSL查询:
GET /_search
{
"query": {
"bool": {
"should": [
{"range": {"include.age.minAge": {"lte": 9}}},
{"range": {"include.age.maxAge": {"gte": 9}}
}
],"minimum_should_match": 2
}
}
}
答案 1 :(得分:0)
您还可以使用integer_range数据类型来验证是否在范围内的值 https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html