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

Top-level inner hits support #308

Open
arinhouck opened this issue Jan 13, 2016 · 2 comments
Open

Top-level inner hits support #308

arinhouck opened this issue Jan 13, 2016 · 2 comments

Comments

@arinhouck
Copy link

I am currently calling this query in curl and works accordingly. I was wondering if there would be a workaround with have this done with a raw query. The problem with calling it in Index.query({}) is that it wraps itself in a "query" key. Where as I need the inner_hits at the same level as the query.

{
  "query": {
    "bool": {
      "should": [
        { "match": { "name": "14\" multitouch notebook" }},
        { "match": { "identifier": "14\" multitouch notebook" }},
        { "match": { "description": "14\" multitouch notebook" }},
        {
          "has_child": {
            "child_type": "attribution_group",
            "query": {
              "bool": {
                "should": [
                  { "match": {"name": "14\" multitouch notebook"} },
                  {
                    "has_child": {
                      "child_type": "specification_attribution",
                      "query": {
                        "bool": {
                          "should": [
                            { "match": {"attribution_values": "14\" multitouch notebook"} }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "inner_hits": {
    "chosen_name": {
      "type": {
        "attribution_group": {
          "query": {
            "match_all": {}
          },
          "inner_hits": {
            "chosen_name2": {
              "type": {
                "specification_attribution": {
                  "query": {
                    "match_all": {}
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

The query can't be wrapped inside of anything else, cannot use the Index.filter { r(hash_here) } because it wraps it in the the filtered layer.

I would see it as something available like Index.query(query_hash).inner_hits(inner_hash) or as a quick solution to allow passing in a hash that isn't wrapped by anything.

@pyromaniac
Copy link
Contributor

Seems like this is a quite new option, I haven't seen it before, hence it is not implemented, but you are able to do a small patch here https://github.com/toptal/chewy/blob/master/lib/chewy/query.rb the same way as other chainable methods are implemented.

@JonathanFrias
Copy link

I made that pull request #955 but I have abandoned it because it looks like you can query inner_hits query by nesting it under your has_child element. While my work seems to generate the query that you're asking for, I'm not sure what the advantage to this would be.

Also to quote the linked elasticsearch docs:

Inner hits can be used by defining an inner_hits definition on a nested, has_child or has_parent query and filter. The structure looks like this:

"<query>" : {
    "inner_hits" : {
        <inner_hits_options>
    }
}

Which seems to contradict that inner_hits needs to be at the same level as query.

Finally, when I did get inner_hits to work, I found them to be too limiting with size option, which means it doesn't work with my use case so I've abandoned that approach entirely.

Seems to me this issue should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants