我正在elasticsearch中搜索事件。每个事件都可以具有特定的开始日期集(以秒为单位),也可以进行活动,直到手动取消为止。在我的搜索查询中,我正在搜索(除其他参数)今天的日期,并希望找到所有事件:
- 从今天开始(日期>今天和数据类型=特定)
- 或正在进行(dateType =正在进行)
我的查询看起来像这样,但它不起作用:
"query":{
"bool":{
"must":[
{
"range":{
"latitude":{
"gte":45.78560033657945,
"lte":46.54954406342055
}
}
},
{
"range":{
"longitude":{
"gte":13.75487411320551,
"lte":14.857968686794491
}
}
},
{
"multi_match":{
"query":"tes",
"type":"phrase_prefix",
"fields":[
"title^3",
"subtitle^2"
]
}
}
],
"should":[
{
"range":{
"validDateUnix":{
"gte":1487026800000
}
}
}
]
}
}
任何帮助将不胜感激。
您需要在 should
零件上工作以捕获这两个约束,现在您只捕获了第一个约束的一半。尝试以下操作:
"query":{
"bool":{
"must":[
{
"range":{
"latitude":{
"gte":45.78560033657945,
"lte":46.54954406342055
}
}
},
{
"range":{
"longitude":{
"gte":13.75487411320551,
"lte":14.857968686794491
}
}
},
{
"multi_match":{
"query":"tes",
"type":"phrase_prefix",
"fields":[
"title^3",
"subtitle^2"
]
}
}
],
"minimum_should_match": 1,
"should":[
{
"bool": {
"filter": [
{
"term": {
"dateType": "specific"
}
},
{
"range":{
"validDateUnix":{
"gte":1487026800000
}
}
}
]
}
},
{
"term": {
"dateType": "on-going"
}
}
]
}
}
{
"id": "7812c801-0000-0000-0000-000000000000",
"title": "Know Your Student Protest Rights",
"subtitle": "Know what you can and can't do. Join our campus communities to help other students understand their rights. Peer to peer advocacy is critical to our approach.",
"whatIsImpact": "The ACLU makes sure that our basic Constitutional rights – to free speech, to privacy, to be innocent until proven guilty – don’t just exist on paper, but also practice. The ACLU enforces the vision that these freedoms be guaranteed to every person in this country. These are our American values.",
"whatIsNeeded": "Our goal is to connect with young Americans so they understand their civic rights.",
"whyIsNeeded": "The ACLU of Northern California is an enduring guardian of justice, fairness, equality, and freedom, working to protect and advance civil liberties for all Californians. This includes students!",
"url": "https://www.aclunc.org",
"address": "Ljubljana, Slovenia",
"dateType": "on-going",
"issues": [],
"latitude": "46.1671294",
"longitude": "14.3058337",
"organization": "68c9c701-0000-0000-98c9-c70100000000",
"organizationName": "Developer test",
"type": "Volunteer"
}