Skip to content

Conversation

picandocodigo
Copy link
Member

Transferred from elastic/elasticsearch-ruby#1083, original PR by @eliskah

Original Pull Request message

This PR should fix following:

When using field collapsing, it is possible to define _source for inner hits, like this:

{
  "collapse": {
    "field" : "user_id",
    "inner_hits" : {
      "name" : "records",
      "size" : 5,
      "_source" : ["content", "updated_at"]
    }
  },
  "_source" : false,
  "size" : 10
}

DSL supports collapsing with inner hits fine, but if I try to define the _source inside the inner_hits block, it's used in the top level _source instead. See this example:

require 'json'
require 'elasticsearch/dsl'

include Elasticsearch::DSL

definition = search do
  collapse :user_id do
    inner_hits :records do
      size 5
      _source ["content", "updated_at"]
    end
  end
  _source false
  size 10
end

puts definition.to_hash.to_json

Returns:

{
  "size": 10,
  "collapse": {
    "field": "user_id",
    "inner_hits": {
      "name": "records",
      "size": 5
    }
  },
  "_source": [
    "content",
    "updated_at"
  ]
}

I would expect to get the query as above: With top level _source value of false and inner hits level _source with the fields "content" and "updated_at".

@h6ah4i
Copy link

h6ah4i commented Mar 22, 2023

+1

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

Successfully merging this pull request may close these issues.

3 participants