2017-02-16 30 views
0

我正在ElasticSearch中搜索事件。每個事件都可以設置特定的開始日期(以秒爲單位),或者事件正在進行,直到手動取消爲止。在我的搜索查詢我正在尋找(在其他參數)有今天的日期,想找到所有事件:Elasticsearch搜索多種日期類型的事件

今天
  • 開始(日期>今天dateType =特定)
  • 或仍在進行中( 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 
       } 
      } 
     } 
     ] 
    } 
} 

任何幫助,將不勝感激。

回答

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" 
      } 
     } 
     ] 
    } 
} 
+0

謝謝您的回答,但似乎並沒有工作。結果包含過去的事件。所以範圍過濾器讓他們通過某種方式。 – Leon

+0

第一部分現在工作正常,我只能過濾新事件,但正在進行的不包括在內。 – Leon

+0

你能展示一個應該與正在進行的約束匹配的示例文檔嗎? – Val

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" 
} 
+0

@Val這裏是適合正在進行的條件的示例文檔。 – Leon

相關問題