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

Key conflicts when field data service load two fields for different types but with same indexName #8772

Closed
coderplay opened this issue Dec 3, 2014 · 1 comment

Comments

@coderplay
Copy link

Let's take a look at the implementation of IndexFieldDataService. getForField(FieldMapper<?> mapper)

    public <IFD extends IndexFieldData<?>> IFD getForField(FieldMapper<?> mapper) {
...
        final String key = fieldNames.indexName();
        IndexFieldData<?> fieldData = loadedFieldData.get(key);
...
                    fieldData = builder.build(index, indexSettings, mapper, cache, circuitBreakerService, indexService.mapperService());
                    loadedFieldData.put(fieldNames.indexName(), fieldData);
...
        return (IFD) fieldData;
    }

This method use FieldMapper's indexName as key, fetch field data for a concurrent HashMap. The indexName of FieldMapper is always from a DocumentMapper, which is built like this

// DocumentMapper.Builder
        public Builder(String index, Settings indexSettings, RootObjectMapper.Builder builder) {
...
            this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1));
...
        }

The new ContentPath(1) will effect all FieldMapper's indexNames of a DocumentMapper. Those indexName won't get a full path with a qualifier.

Here is an FieldMapper example which passed into IndexFieldDataService. getForField(FieldMapper<?> mapper)

names = {org.elasticsearch.index.mapper.FieldMapper$Names@5182}
name = {java.lang.String@7248}"country"
indexName = {java.lang.String@7249}"country"
indexNameClean = {java.lang.String@7248}"country"
fullName = {java.lang.String@7250}"country"
sourcePath = {java.lang.String@7250}"country"

When two two fields for different types but with same indexName passed into IndexFieldDataService. getForField(FieldMapper<?> mapper), the second call will retrieve a wrong field data since its indexName will match the key from the first method call which will be already in loadedFieldData.

Please correct me if I misunderstand the logic of this part.

@clintongormley
Copy link
Contributor

Hi @coderplay

You are correct. We are removing index_name (#6677) and requiring that fields of the same name in different types in the same index have the same mappings (#4081).

thanks

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