How to query count of nested elasticsearch inner_hits document

How to count of nested elasticsearch inner_hits document

This is Mappings and Data

PUT /xxx_index
{
  "mappings": {
    "doc": {
      "properties": {
        "interaction": {
          "type": "object",
          "properties": {
            "activity": {
              "type": "nested",
              "properties": {
                "start_time": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  }
}


POST /xxx_index/doc
{
  "interaction": {
    "activity": [
      {
        "start_time": 1
      },
     {
        "start_time": 1
      },
      {
        "start_time": 2
      }
    ]
  }
}

POST /xxx_index/doc
{
  "interaction": {
    "activity": [
      {
        "start_time": 1
      },
     {
        "start_time": 2
      },
      {
        "start_time": 2
      }
    ]
  }
}


I want to query interaction.activity.start_time == 2 and interaction.activity the nested document count > 1

but, i don't know how to write query

next , here's my query synatx, it is return null result

GET zentrust_cn_test:label_user/_search
{
  "query": {
    "nested": {
      "path": "interaction.activity",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "interaction.activity.start_time": {
                  "value": "1"
                }
              }
            },
            {
              "script": {
                "script": "doc['interaction.activity.start_time'].values.size() > 1"
              }
            }
          ]
        }
      }
    }
  }
}

Return Result

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

I very thank you much!

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