olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch

Home Page:https://olivere.github.io/elastic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The collapse query does not support multiple inner_hit conditions

may11544 opened this issue · comments

Please use the following questions as a guideline to help me answer
your issue/question without further inquiry. Thank you.

Which version of Elastic are you using?

  • elastic.v7 (for Elasticsearch 7.x)
  • elastic.v6 (for Elasticsearch 6.x)
  • elastic.v5 (for Elasticsearch 5.x)
  • elastic.v3 (for Elasticsearch 2.x)
  • elastic.v2 (for Elasticsearch 1.x)

The elasticsearch query statement I want is like this

{
  "_source": {
    "includes": [
      "flow_id"
    ]
  },
  "aggregations": {
    "collapse_count": {
      "cardinality": {
        "field": "collapse_field.keyword",
        "precision_threshold": 40000
      }
    }
  },
  "collapse": {
    "field": "collapse_field.keyword",
    "inner_hits": [
      {
        "name": "severity",
        "size": 0
      },
      {
        "name": "result",
        "size": 0
      }
    ]
  },
  "from": 0,
  "query": {
    "bool": {
      "must": {
        "exists": {
          "field": "collapse_field"
        }
      }
    }
  },
  "size": 10,
  "sort": [
    {
      "timestamp": {
        "order": "desc",
        "unmapped_type": "long"
      }
    }
  ]
}

Note that inner_hits is an array.There are also corresponding usage methods in the official documents:
https://www.elastic.co/guide/en/elasticsearch/reference/7.0/search-request-collapse.html
like this:

{
    "query": {
        "match": {
            "message": "elasticsearch"
        }
    },
    "collapse" : {
        "field" : "user", 
        "inner_hits": [
            {
                "name": "most_liked",  
                "size": 3,
                "sort": ["likes"]
            },
            {
                "name": "most_recent", 
                "size": 3,
                "sort": [{ "date": "asc" }]
            }
        ]
    },
    "sort": ["likes"]
}

But I found that in the implementation of CollapseBuilder, innerHit can only be an object and not an array.

type CollapseBuilder struct {
	field                      string
	innerHit                   *InnerHit
	maxConcurrentGroupRequests *int
}

When I tried to write elastic.NewCollapseBuilder().InnerHit().InnerHit(), I found that the inner_hit in the last query statement would be overwritten by the last one.

I am eager to know if there is a problem with my writing method or it is not yet supported that inner_hit is an array.

Thank you so much!

Upgrading the version can solve this problem