Elasticsearch 根据属性数量查找匹配文档

Elasticsearch find match document base on number of properties

我在 elastic search 中有一些文档

doc1 -> name: name1  
doc2 -> name: name1, otherprop: prop1  
doc3 -> name: name1, otherprop: prop1, otherprop2: prop2  

我的目标是按名称获取 doc1,但查询 return 所有三个文档
我试图通过名称和最小值(属性计数)获取 doc1,但我的查询是 return 或什么都没有或所有匹配文档

{
  "query": {
    "bool": {
      "filter": [
        { "term": { "name": "name1"   }}
      ]
    }
  },
  "aggs": {
    "models": {
      "terms": { "field": "name" } 
    }
  }
}

我的idea如何才能只得到doc1?
谢谢

要实现这样的功能,您可以在索引期间添加字段数并在查询期间检查字段数,要更新您的所有文档,您可以通过查询使用此更新:

查询更新

POST [index name]/_update_by_query
{
    "query": {
        "match_all": {}
    }, 
    "script": {
       "source": "ctx._source.fieldsCount = ctx._source.size()"
    }
}

然后您可以使用 FieldsCount 字段来编写您的查询。