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

Parent/child inner hits not containing the fields values #13898

Closed
albanm opened this issue Oct 2, 2015 · 2 comments
Closed

Parent/child inner hits not containing the fields values #13898

albanm opened this issue Oct 2, 2015 · 2 comments

Comments

@albanm
Copy link

albanm commented Oct 2, 2015

Hello,

The parent/child inner hits seem to support requesting only the '_source' field. Inner hits on nested objects on the contrary support asking for any field.

The documentation is not extremely clear on the subject, but I think it should work.

I have this behavior on ElasticSearch 1.7.2.

This script reproduces the problem in the more concise way i could think of:

printf "Delete index:\n\n"
curl -XDELETE localhost:9200/test

printf "\n\nPrepare mappings with parent/child relationship and some nested object:\n\n"
curl -XPUT localhost:9200/test -d '{
  "mappings": {
    "company": {
      "properties": {
        "addresses": {
          "type": "nested"
        }
      }
    },
    "employee": {
      "_parent": {
        "type": "company"
      }
    }
  }
}'

printf "\n\nInsert a company with nested address:\n\n"
curl -XPUT localhost:9200/test/company/mgdis -d '{
  "companyName": "MGDIS",
  "addresses": [{
    "city": "Vannes",
    "country": "France"
  }]
}'

printf "\n\nInsert a employee child of the company:\n\n"
curl -XPUT localhost:9200/test/employee/alban?parent=mgdis -d '{
  "name": "Alban Mouton"
}'

printf "\n\nFlush index:\n\n"
curl -XPOST 'http://localhost:9200/test/_flush'

printf "\n\nSearch a company with nested addresses in inner hits. The field 'city' IS PRESENT:\n\n"
curl -XPOST localhost:9200/test/company/_search -d '{
  "query": {
    "nested": {
      "path": "addresses",
      "query": {
        "match_all": {}
      },
      "inner_hits": {
        "fields": ["city"]
      }
    }
  }
}'

printf "\n\nSearch an employee with parent company in inner hits. The field 'companyName' SHOULD BE PRESENT:\n\n"
curl -XPOST localhost:9200/test/employee/_search -d '{
  "query": {
    "has_parent": {
      "parent_type": "company",
      "query": {
        "match_all": {}
      },
      "inner_hits": {
        "fields": ["companyName"]
      }
    }
  }
}'

printf "\n\nSearch a company with child employee in inner hits. The field 'name' SHOULD BE PRESENT:\n\n"
curl -XPOST localhost:9200/test/company/_search -d '{
  "query": {
    "has_child": {
      "type": "employee",
      "query": {
        "match_all": {}
      },
      "inner_hits": {
        "fields": ["name"]
      }
    }
  }
}'
@martijnvg
Copy link
Member

Hi @albanm if you remove the company/employee type from the url then I expect the last two queries to work.

There is an issue with the inner query wrapped has_child/has_parent can't access mapping information from the child or parent type if a type is specified in the url. This has been fixed in 2.0.

@albanm
Copy link
Author

albanm commented Oct 2, 2015

Indeed it works !

Thanks a lot for the quick response.

@albanm albanm closed this as completed Oct 2, 2015
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

2 participants