2016-01-21 19 views
0

表達SQL嵌套條件我有這樣的SQL片段:在ElasticSearch

and (
    (notrequired is not null and notrequired <= datedue) 
    or 
    (datefulfilled is not null and datefulfilled <= datedue) 
) 

我試圖表達這樣的:

""or"": [ 
    {{ 
     ""and"": [ 
      {{ 
       ""exists"": {{ ""field"": ""NotRequired"" }} 
      }}, 
      {{ 
       ""script"": {{ 
        ""script"": ""doc['NotRequired'].value <= doc['DateDue'].value"" 
       }} 
      }} 
     ], 
     ""and"": [ 
      {{ 
       ""exists"": {{ ""field"": ""DateFulfilled"" }} 
      }}, 
      {{ 
       ""script"": {{ 
        ""script"": ""doc['DateFulfilled'].value <= doc['DateDue'].value"" 
       }} 
      }} 
     ] 
    }} 
] 

外最and作爲上聚集體的過濾器做到這一點應用了一個過濾器。因此,有一個

aggs: { 
    "name": { 
     filter: {}, 
     aggs: { 
      "inner" : { 
       filter: {} 
      } 
     } 
    } 
} 

內過濾器是其中施加and SQL片段內的一切。所以通過我的推算,因爲你在過濾器內進行過濾,所以應用and

請原諒ES片段的逃脫。

回答

0

我已經格式化搜索錯誤:

""or"": [ 
    {{ 
     ""and"": [ 
      {{ 
       ""exists"": {{ ""field"": ""NotRequired"" }} 
      }}, 
      {{ 
       ""script"": {{ 
        ""script"": ""doc['NotRequired'].value <= doc['DateDue'].value"" 
       }} 
      }} 
     ] 
    }}, 
    {{ 
     ""and"": [ 
      {{ 
       ""exists"": {{ ""field"": ""DateFulfilled"" }} 
      }}, 
      {{ 
       ""script"": {{ 
        ""script"": ""doc['DateFulfilled'].value <= doc['DateDue'].value"" 
       }} 
      }} 
     ] 
    }} 
] 

每個and是它自己的對象中需要!