2017-10-19 3 views
1

は私がElasticsearchで次のクエリを持っている:Elasticsearchの複数のフィールドにブールフィルタを作成するにはどうすればよいですか?

{ 
    "script_fields": { 
    "travel_time": { 
     "script": { 
     "inline": "doc['DateTo'].value - doc['DateFrom'].value" 
     } 
    } 
    }, 
    "stored_fields": [ 
    "_source" 
    ], 
    "query": { 
    "bool": { 
     "filter": { 
     "exists": { 
      "field": "DateTo" 
     } 
     } 
    } 
    } 
} 

私はexistsフィルタにDateFromを追加することができますどのように?

+0

あなたがelasticsearchのどのバージョンを使用していますか? –

+0

@TobiasGassmann:5.5 – Dinosaurius

答えて

1

あなたは、複数のexists条件を追加することができます

"query": { 
    "bool": { 
     "filter": [ 
     { 
     "exists": { 
      "field": "DateFrom" 
     } 
     }, 
     { 
     "exists": { 
      "field": "DateTo" 
     } 
     }, 
     { 
     "script": { 
      "script": { 
      "inline": "doc['DateTo'].value - doc['DateFrom'].value > 0" 
      } 
     } 
     } 
     ] 
    } 
    } 
+0

Ah、ok。 value - doc ['DateFrom']。value "は正の数値でなければなりません? – Dinosaurius

+0

私の更新された回答を見る – Val

関連する問題