equinor / fmu-sumo

Interaction with Sumo in the FMU context
https://fmu-sumo.readthedocs.io/en/latest/
Apache License 2.0
0 stars 6 forks source link

Add "has" filter to cases #325

Closed equinor-ruaj closed 5 months ago

equinor-ruaj commented 5 months ago

First version solution to: https://github.com/equinor/fmu-sumo/issues/324

First version to implement: Add "has" keyword to case filter: filter cases where the case has at least one child with the specified "has" values.

cases = sumo.cases

cases = cases.filter(has={"data.content": "seismic", "data.time.t0.label": "base", "data.time.t1.label": "monitor"})

# With asset filter
cases = cases.filter(has={"data.content": "seismic", "data.time.t0.label": "base", "data.time.t1.label": "monitor"}, asset="Drogon")

-> cases == all cases that has child data matching the "has" filter
roywilly commented 5 months ago

The corresponding query, from Raymond:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "data.content.keyword": {
              "value": "seismic"
            }
          }
        },
        {
          "term": {
            "data.time.t0.label.keyword": {
              "value": "base"
            }
          }
        },
        {
          "term": {
            "data.time.t1.label.keyword": {
              "value": "monitor"
            }
          }
        }
      ]
    }
  },
  "_source": ["data.time"],
  "aggs": {
    "case": {
      "composite": {
        "sources": [
          {
            "cases": {
              "terms": {
                "field": "fmu.case.uuid.keyword"
              }
            }
          }
        ],
        "size": 1000
      }
    }
  }, 
  "size": 1,
  "track_total_hits": true
}