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

Strange behaviour of fields API with mixed object notation #68215

Closed
cbuescher opened this issue Jan 29, 2021 · 7 comments · Fixed by #68540
Closed

Strange behaviour of fields API with mixed object notation #68215

cbuescher opened this issue Jan 29, 2021 · 7 comments · Fixed by #68540
Assignees
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v7.10.0

Comments

@cbuescher
Copy link
Member

It appears we can currently index and retrieve documents with mixed object notation like this:

PUT my-index-000001/_doc/1
{
  "obj.products" : { "manufacturer" : "Supersoft" } ,
  "obj" : {
    "products" : 
       { "manufacturer" : "HyperSmart" }
  }
}

When searching on field obj.products.manufacturer we get a hit for both terms "Supersoft" and "HyperSmart".
However, the fields API output only returns second value:

POST /my-index-000001/_search
{
  "query": {
            "match": {
              "obj.products.manufacturer": "Supersoft"
            }
    },
  "_source" : false,
  "fields" : ["*"]
}

returns

       "fields" : {
          "obj.products.manufacturer.keyword" : [
            "HyperSmart"
          ],
          "obj.products.manufacturer" : [
            "HyperSmart"
          ]
        }

The same output is produced when searching for "HyperSmart". Tested on 7.10.0.

@cbuescher cbuescher added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types needs:triage Requires assignment of a team area label v7.10.0 labels Jan 29, 2021
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jan 29, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@javanna
Copy link
Member

javanna commented Jan 29, 2021

@cbuescher have you checked the mappings for the created index? I would hope that there is one obj.products in there, in the object form.

@cbuescher
Copy link
Member Author

@javanna the mapping looks fine to me:

{
  "my-index-000001" : {
    "mappings" : {
      "properties" : {
        "obj" : {
          "properties" : {
            "products" : {
              "properties" : {
                "manufacturer" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

@javanna
Copy link
Member

javanna commented Jan 29, 2021

Cool, sounds like the fields API should return both values then?

@romseygeek
Copy link
Contributor

Possibly related to #65539

@romseygeek
Copy link
Contributor

Definitely related! This is actually something that @jtibshirani called out when reviewing #65539 - I had fixed this exact case for XContentMapValues.extractRawValues() but not for XContentMapValues.extractValue(), and SourceValueFetcher uses the latter. I wonder if we can just use the former instead, which would also allow us to remove the complicated array nesting logic in SourceValueFetcher, or if that will break something else?

@javanna javanna removed the needs:triage Requires assignment of a team area label label Jan 29, 2021
@jtibshirani
Copy link
Contributor

Thanks @cbuescher for filing this, I forgot to open a follow-up about it after reviewing #65539.

I wonder if we can just use the former instead, which would also allow us to remove the complicated array nesting logic in SourceValueFetcher, or if that will break something else?

We didn't use XContentMapValues.extractRawValues() because it won't return object values. For example, if you have a geopoint structured as an object with lat and lon fields, then that method won't be able to extract it.

@cbuescher cbuescher self-assigned this Feb 4, 2021
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this issue Feb 4, 2021
Currently, when a document source mixed json object and dotted syntax like e.g.
{ "foo" : { "bar" : 0 }, "foo.bar" : 1}, extracting the values from the source
map via XContentMapValues#extractValue returns after the first value for a path
has been found. Instead we should exhaust all possibilities and return a list of
objects of we find more than one value when extending the lookup path.

Closes elastic#68215
cbuescher pushed a commit that referenced this issue Feb 11, 2021
Currently, when a document source mixed json object and dotted syntax like e.g.
{ "foo" : { "bar" : 0 }, "foo.bar" : 1}, extracting the values from the source
map via XContentMapValues#extractValue returns after the first value for a path
has been found. Instead we should exhaust all possibilities and return a list of
objects of we find more than one value when extending the lookup path.

Closes #68215
cbuescher pushed a commit that referenced this issue Feb 11, 2021
Currently, when a document source mixed json object and dotted syntax like e.g.
{ "foo" : { "bar" : 0 }, "foo.bar" : 1}, extracting the values from the source
map via XContentMapValues#extractValue returns after the first value for a path
has been found. Instead we should exhaust all possibilities and return a list of
objects of we find more than one value when extending the lookup path.

Closes #68215
cbuescher pushed a commit that referenced this issue Feb 11, 2021
Currently, when a document source mixed json object and dotted syntax like e.g.
{ "foo" : { "bar" : 0 }, "foo.bar" : 1}, extracting the values from the source
map via XContentMapValues#extractValue returns after the first value for a path
has been found. Instead we should exhaust all possibilities and return a list of
objects of we find more than one value when extending the lookup path.

Closes #68215
@javanna javanna added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v7.10.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants