Skip to content

Commit

Permalink
Add multi_field support for Mapper externalValue (plugins)
Browse files Browse the repository at this point in the history
In context of mapper attachment and other mapper plugins, when dealing with multi fields, sub fields never get the `externalValue` although it was set.

Here is a full script which reproduce the issue when used with mapper attachment plugin:

```
DELETE /test

PUT /test
{
    "mappings": {
        "test": {
            "properties": {
                "f": {
                    "type": "attachment",
                    "fields": {
                        "f": {
                            "analyzer": "english",
                            "fields": {
                                "no_stemming": {
                                    "type": "string",
                                    "store": "yes",
                                    "analyzer": "standard"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

PUT /test/test/1
{
    "f": "VGhlIHF1aWNrIGJyb3duIGZveGVz"
}

GET /test/_search
{
    "query": {
        "match": {
           "f": "quick"
        }
    }
}

GET /test/_search
{
    "query": {
        "match": {
           "f.no_stemming": "quick"
        }
    }
}

GET /test/test/1?fields=f.no_stemming
```

Related to elastic/elasticsearch-mapper-attachments#57

Closes #5402.
  • Loading branch information
dadoonet committed Jul 25, 2014
1 parent 655157c commit 11eced0
Show file tree
Hide file tree
Showing 9 changed files with 868 additions and 270 deletions.
Expand Up @@ -248,10 +248,10 @@ public DocumentMapper build(DocumentMapperParser docMapperParser) {
}


private CloseableThreadLocal<ParseContext> cache = new CloseableThreadLocal<ParseContext>() {
private CloseableThreadLocal<ParseContext.InternalParseContext> cache = new CloseableThreadLocal<ParseContext.InternalParseContext>() {
@Override
protected ParseContext initialValue() {
return new ParseContext(index, indexSettings, docMapperParser, DocumentMapper.this, new ContentPath(0));
protected ParseContext.InternalParseContext initialValue() {
return new ParseContext.InternalParseContext(index, indexSettings, docMapperParser, DocumentMapper.this, new ContentPath(0));
}
};

Expand Down Expand Up @@ -484,7 +484,7 @@ public ParsedDocument parse(SourceToParse source) throws MapperParsingException
}

public ParsedDocument parse(SourceToParse source, @Nullable ParseListener listener) throws MapperParsingException {
ParseContext context = cache.get();
ParseContext.InternalParseContext context = cache.get();

if (source.type() != null && !source.type().equals(this.type)) {
throw new MapperParsingException("Type mismatch, provide type [" + source.type() + "] but mapper is of type [" + this.type + "]");
Expand Down

0 comments on commit 11eced0

Please sign in to comment.