Join two searches with nested field

hello , I have been trying to join those two searches , but I didnt managed .
I want to do this -
SELECT user-data WHERE company.id = 1 AND timestamp BETWEEEN 2023-05-04 - 2023-06-05
// RESULT 100

GET /user-data/_search
{
  "query": {
    "nested": {
      "path": "company",
      "query": {
        "bool": {
          "must": [
            { "match": { "company.id": 1 } }
          ]
        }
      }
    }
  }
}

// RESULT 20

GET /user-data/_search
{
 "query": {
    "bool": {
     "must": [
        { "range": {
            "timestamp": {
              "gte": "2023-05-04",
               "lte": "2023-06-05"
            }
          }
        }
      ]
    }
  }
}

May be something like:

GET /user-data/_search
{
 "query": {
    "bool": {
     "must": [
{
    "nested": {
      "path": "company",
      "query": {
            "match": { "company.id": 1 }
        }
      }
    }
  },
        { 
          "range": {
            "timestamp": {
              "gte": "2023-05-04",
               "lte": "2023-06-05"
            }
          }
        }
      ]
    }
  }
}

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.