Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The collapse query does not support multiple inner_hit conditions #1671

Closed
1 of 5 tasks
may11544 opened this issue Jun 1, 2023 · 1 comment
Closed
1 of 5 tasks

The collapse query does not support multiple inner_hit conditions #1671

may11544 opened this issue Jun 1, 2023 · 1 comment

Comments

@may11544
Copy link

may11544 commented Jun 1, 2023

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!

@may11544
Copy link
Author

may11544 commented Jun 2, 2023

Upgrading the version can solve this problem

@may11544 may11544 closed this as completed Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant