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 query against documents with multiple nested fields with same second-level field names only finds hits for the first-defined nested field #19193

Closed
jaimemarijke opened this issue Jun 30, 2016 · 1 comment

Comments

@jaimemarijke
Copy link

Elasticsearch version: 1.7.3

JVM version: 1.7.0_101

OS version: Ubuntu 14.04.4 LTS

Description of the problem including expected versus actual behavior:
I create a document with several nested fields on it. Then I added second-level fields of the same name on each of those nested fields. Then I tried a nested query against each of the paths, and found that only the first-defined path succeeded

Expected: Performing a nested query when a document has multiple nested fields with the same second-level field names succeeds

Actual: I only get hits for matches on the nested field that was defined first.

Steps to reproduce:

  1. Create an index and document type with nested field mappings. Add a document which adds a field of the same name to each nested field.
PUT /test_index

PUT /test_index/_mappings/test_doc
{
  "properties": {
    "field1": {
      "type": "nested"
    },
    "field2": {
      "type": "nested"
    },
    "field3": {
      "type": "nested"
    }
  }
}

PUT /test_index/test_doc/1
{
  "field1": {
    "value": "100"
  },
  "field2": {
    "value": "100"
  },
  "field3": {
    "value": "100"
  }
}

2 . Check that nested mappings are defined correctly

GET /test_index/_mappings/test_doc
{
   "test_index": {
      "mappings": {
         "test_doc": {
            "properties": {
               "field1": {
                  "type": "nested",
                  "properties": {
                     "value": {
                        "type": "string"
                     }
                  }
               },
               "field2": {
                  "type": "nested",
                  "properties": {
                     "value": {
                        "type": "string"
                     }
                  }
               },
               "field3": {
                  "type": "nested",
                  "properties": {
                     "value": {
                        "type": "string"
                     }
                  }
               }
            }
         }
      }
   }
}

3 . Try performing a nested filter query against the first-defined nested field. See that it correctly gets a hit.

GET /test_index/_search
{
  "query": {
    "filtered": {
      "filter": {
        "nested": {
          "path": "field1",
          "filter": {
              "term": { "value": "100" }
          }
        }
      }
    }
  }
}
{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_index",
            "_type": "test_doc",
            "_id": "1",
            "_score": 1,
            "_source": {
               "field1": {
                  "value": "100"
               },
               "field2": {
                  "value": "100"
               },
               "field3": {
                  "value": "100"
               }
            }
         }
      ]
   }
}

4 . Try performing a nested filter query against the the later-defined nested fields. See that they do not get hits.

GET /test_index/_search
{
  "query": {
    "filtered": {
      "filter": {
        "nested": {
          "path": "field2",
          "filter": {
              "term": { "value": "100" }
          }
        }
      }
    }
  }
}
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}

Provide logs (if relevant):

@rjernst
Copy link
Member

rjernst commented Jun 30, 2016

This was a known issue in 1.x, and was fixed in 2.x. See #8870

@rjernst rjernst closed this as completed Jun 30, 2016
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