Elasticsearch搜索具有多种日期类型的事件

时间:2017-02-16 20:27:38

标签: events elasticsearch

我在ElasticSearch中搜索事件。每个事件都可以设置特定的开始日期(以秒为单位),或者事件正在进行,直到手动取消。在我的搜索查询中,我正在搜索(以及其他参数)今天的日期,并希望找到所有事件:

  • 今天开始(日期>今天和dateType =具体)
  • OR正在进行中(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
              }
            }
        }
      ]
  }
}

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:0)

您需要处理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"
           }
        }
      ]
  }
}

答案 1 :(得分:0)

{
  "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"
}