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

Dynamic mappings fail when a single document generates inconsistent mapping updates #15377

Open
jpountz opened this issue Dec 10, 2015 · 12 comments
Labels
>docs General docs changes help wanted adoptme :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Docs Meta label for docs team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@jpountz
Copy link
Contributor

jpountz commented Dec 10, 2015

For instance indexing the following document would fail if the foo.bar field is not mapped explicitly:

{
  "foo": [
    {
      "bar": "baz"
    },
    {
      "bar": 42
    }
  ]
}

The reason is that mapping updates for the 2 sub documents are generated independently (one triggers the creation of a string field and the other one of a long field) but they can't be reconciliated in order to generate the mapping update that will be sent to the master node.

Bug report courtesy of Benjamin Gathmann at https://discuss.elastic.co/t/coerce-long-to-double-not-working/36882.

@jpountz jpountz added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types labels Dec 10, 2015
@clintongormley clintongormley added the help wanted adoptme label Dec 14, 2015
@davidvgalbraith
Copy link

Right! So what's the intended behavior?

@jpountz
Copy link
Contributor Author

jpountz commented Dec 21, 2015

@davidvgalbraith Good question, I think I'm leaning towards documenting this as a limitation of dynamic mappings. I think it's fair that dynamic mappings don't work if a single document does not use consistent json types for fields that have the same path?

We could potentially avoid conflicts by using the most generic type (ie. string > double, double > long, etc.) but I'm afraid this would hide issues more than it would solve problems. I'd rather rely on something more explicit like dynamic templates.

@abulhol
Copy link

abulhol commented Dec 21, 2015

Thank you for mentioning dynamic templates. I will try this out. The point is that like in my case, you simply have to deal with the data you have, and throwing this data into Elasticsearch is not quite as easy as I expected.

@clintongormley
Copy link
Contributor

Here's another example where the fact that it doesn't work is more unexpected:

PUT /speed/record/1
{
  "speed_rec": [
    {
      "speed": 61.23
    },
    {
      "speed": 61
    }
  ]
}

@jpountz
Copy link
Contributor Author

jpountz commented Mar 24, 2016

True, but when not all numbers have a dot, you are going to have problems anyway. For instance if the first document only contains integers, the field will be mapped as a long and the decimal part of documents that come afterwards will be truncated. (Related to #16018)

@cssccarvalho
Copy link

Hello. I would like to add that if someone wants to use the global coerce setting to disable this kind of validation. It doesn't work. I have tried with the latest docker elasticsearch official image.

@ibrahima
Copy link
Contributor

ibrahima commented Apr 5, 2016

I recognize that this is not necessarily a "solvable" problem for the int vs float case, but isn't it reasonable to just index all other fields anyway and make a note of the error? The current behavior I'm experiencing is the same as described by @clintongormley , and it results in that log message just being dropped from the index. Is there some way I can at least let this message be parsed and indexed and just keep those conflicted fields out of the index?

@javanna
Copy link
Member

javanna commented Mar 16, 2018

@elastic/es-search-aggs

@glestel
Copy link

glestel commented Sep 24, 2018

I've been pulling a lot of hair because of some ill formatted API returning me documents to index with a content similar to

"parents": [
        {
          "itemId": 18124
        },
        {
          "itemId": ""
        }
]

And dynamic template couldn't do anything, even with

"mapping": {
          "coerce": "true",
          "ignore_malformed": "true"
}

I think an option to default to the most generic type would be usefull

@rjernst rjernst added the Team:Search Meta label for search team label May 4, 2020
@javanna javanna added >docs General docs changes and removed >bug labels Oct 13, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Docs Meta label for docs team label Oct 13, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-docs (Team:Docs)

@elasticsearchmachine
Copy link
Collaborator

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

@abdonpijpelink abdonpijpelink removed their assignment Jan 26, 2024
@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
@elasticsearchmachine
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>docs General docs changes help wanted adoptme :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Docs Meta label for docs team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

No branches or pull requests