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

Nested document wrongly indexed? #9074

Closed
Enzo90910 opened this issue Dec 26, 2014 · 1 comment
Closed

Nested document wrongly indexed? #9074

Enzo90910 opened this issue Dec 26, 2014 · 1 comment

Comments

@Enzo90910
Copy link

(Tested on ES 1.3.4 and 1.4.2)
When I do the following commands:

// Creating index
curl -XPUT 'http://localhost:9200/test_index'

// Creating mapping with two nested properties, customData and experiments
curl -XPUT 'http://localhost:9200/test_index/_mapping/test_mapping' -d '{"test_mapping":{"properties":{"customData":{"type":"nested","properties":{"id":{"type":"integer","doc_values":true},"value":{"type":"string","index":"not_analyzed","doc_values":true}}},"experiments":{"type":"nested","properties":{"id":{"type":"long","doc_values":true},"variationId":{"type":"long","doc_values":true}}}}}}'

// Creating document in mapping
curl -XPUT 'http://localhost:9200/test_index/test_mapping/test_document' -d '{"experiments":[{"id":13048,"variationId":83517}],"customData":[]}'

// Querying for same document using second subproperty of experiments, everything OK
curl -XGET 'http://localhost:9200/test_index/_search?size=1&pretty=true' -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"_id":"test_document"}},{"nested":{"path":"experiments","filter":{"term":{"variationId":83517}}}}]}}}}'

=> ... "hits" : { "total" : 1 ...}

// Querying for same document using first subproperty of experiments, DOES NOT FIND DOCUMENT
curl -XGET 'http://localhost:9200/test_index/_search?size=1&pretty=true' -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"_id":"test_document"}},{"nested":{"path":"experiments","filter":{"term":{"id":13048}}}}]}}}}'
curl -XDELETE 'http://http://localhost:9200/test_index/'

=> ... "hits" : { "total" : 0 ...}

If I do the same commands but with a mapping containing only the second nested property, everything works as expected:
curl -XPUT 'http://localhost:9200/test_index'
curl -XPUT 'http://localhost:9200/test_index/_mapping/test_mapping' -d '{"test_mapping":{"properties":{"experiments":{"type":"nested","properties":{"id":{"type":"long","doc_values":true},"variationId":{"type":"long","doc_values":true}}}}}}'
curl -XPUT 'http://http://localhost:9200/test_index/test_mapping/test_document' -d '{"experiments":[{"id":13048,"variationId":83517}]}'

// Querying for same document using second subproperty of experiments, everything OK
curl -XGET 'http://localhost:9200/test_index/_search?size=1&pretty=true' -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"_id":"test_document"}},{"nested":{"path":"experiments","filter":{"term":{"variationId":83517}}}}]}}}}'
=> ... "hits" : { "total" : 1 ...}

// Querying for same document using first subproperty of experiments, everything OK
curl -XGET 'http://localhost:9200/test_index/_search?size=1&pretty=true' -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"_id":"test_document"}},{"nested":{"path":"experiments","filter":{"term":{"id":13048}}}}]}}}}'

=> ... "hits" : { "total" : 1 ...}

I am becoming crazy, has anyone else seen the same problems?

@clintongormley
Copy link
Contributor

Hi @Enzo90910

You're not going crazy :) The problem is that you have two nested fields called id, and you're not using the whole path name. If you change your filter from:

            "term": {
              "id": 13048
            }

to

            "term": {
              "experiments.id": 13048
            }

then everything works correctly.

Issue #8872 will enforce the requirement to use the full path name on all fields

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