use the same improved fields extraction in get api
This commit is contained in:
parent
9a13763315
commit
8c322b4cc2
|
@ -189,25 +189,36 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
||||||
if (gFields != null && gFields.length > 0) {
|
if (gFields != null && gFields.length > 0) {
|
||||||
SearchLookup searchLookup = null;
|
SearchLookup searchLookup = null;
|
||||||
for (String field : gFields) {
|
for (String field : gFields) {
|
||||||
String script = null;
|
Object value = null;
|
||||||
if (field.contains("_source.") || field.contains("doc[")) {
|
if (field.contains("_source.") || field.contains("doc[")) {
|
||||||
script = field;
|
|
||||||
} else {
|
|
||||||
FieldMappers x = docMapper.mappers().smartName(field);
|
|
||||||
if (x != null && !x.mapper().stored()) {
|
|
||||||
script = "_source." + x.mapper().names().fullName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (script != null) {
|
|
||||||
if (searchLookup == null) {
|
if (searchLookup == null) {
|
||||||
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
||||||
}
|
}
|
||||||
SearchScript searchScript = scriptService.search(searchLookup, "mvel", script, null);
|
SearchScript searchScript = scriptService.search(searchLookup, "mvel", field, null);
|
||||||
searchScript.setNextReader(docIdAndVersion.reader);
|
searchScript.setNextReader(docIdAndVersion.reader);
|
||||||
searchScript.setNextDocId(docIdAndVersion.docId);
|
searchScript.setNextDocId(docIdAndVersion.docId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object value = searchScript.run();
|
value = searchScript.run();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
if (logger.isTraceEnabled()) {
|
||||||
|
logger.trace("failed to execute get request script field [{}]", e, field);
|
||||||
|
}
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FieldMappers x = docMapper.mappers().smartName(field);
|
||||||
|
if (x == null || !x.mapper().stored()) {
|
||||||
|
if (searchLookup == null) {
|
||||||
|
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
||||||
|
searchLookup.setNextReader(docIdAndVersion.reader);
|
||||||
|
searchLookup.setNextDocId(docIdAndVersion.docId);
|
||||||
|
}
|
||||||
|
value = searchLookup.source().extractValue(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
if (fields == null) {
|
if (fields == null) {
|
||||||
fields = newHashMapWithExpectedSize(2);
|
fields = newHashMapWithExpectedSize(2);
|
||||||
}
|
}
|
||||||
|
@ -217,12 +228,6 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
||||||
fields.put(field, getField);
|
fields.put(field, getField);
|
||||||
}
|
}
|
||||||
getField.values().add(value);
|
getField.values().add(value);
|
||||||
} catch (RuntimeException e) {
|
|
||||||
if (logger.isTraceEnabled()) {
|
|
||||||
logger.trace("failed to execute get request script field [{}]", e, script);
|
|
||||||
}
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,23 +266,14 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
||||||
value = docMapper.TTLFieldMapper().valueForSearch(source.timestamp + source.ttl);
|
value = docMapper.TTLFieldMapper().valueForSearch(source.timestamp + source.ttl);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String script = null;
|
|
||||||
if (field.contains("_source.")) {
|
if (field.contains("_source.")) {
|
||||||
script = field;
|
|
||||||
} else {
|
|
||||||
FieldMappers x = docMapper.mappers().smartName(field);
|
|
||||||
if (x != null) {
|
|
||||||
script = "_source." + x.mapper().names().fullName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (script != null) {
|
|
||||||
if (searchLookup == null) {
|
if (searchLookup == null) {
|
||||||
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
||||||
}
|
}
|
||||||
if (sourceAsMap == null) {
|
if (sourceAsMap == null) {
|
||||||
sourceAsMap = SourceLookup.sourceAsMap(source.source.bytes(), source.source.offset(), source.source.length());
|
sourceAsMap = SourceLookup.sourceAsMap(source.source.bytes(), source.source.offset(), source.source.length());
|
||||||
}
|
}
|
||||||
SearchScript searchScript = scriptService.search(searchLookup, "mvel", script, null);
|
SearchScript searchScript = scriptService.search(searchLookup, "mvel", field, null);
|
||||||
// we can't do this, only allow to run scripts against the source
|
// we can't do this, only allow to run scripts against the source
|
||||||
//searchScript.setNextReader(docIdAndVersion.reader);
|
//searchScript.setNextReader(docIdAndVersion.reader);
|
||||||
//searchScript.setNextDocId(docIdAndVersion.docId);
|
//searchScript.setNextDocId(docIdAndVersion.docId);
|
||||||
|
@ -289,10 +285,16 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
||||||
value = searchScript.run();
|
value = searchScript.run();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("failed to execute get request script field [{}]", e, script);
|
logger.trace("failed to execute get request script field [{}]", e, field);
|
||||||
}
|
}
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (searchLookup == null) {
|
||||||
|
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
||||||
|
searchLookup.source().setNextSource(SourceLookup.sourceAsMap(source.source.bytes(), source.source.offset(), source.source.length()));
|
||||||
|
}
|
||||||
|
value = searchLookup.source().extractValue(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
|
|
@ -38,7 +38,6 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kimchy (shay.banon)
|
* @author kimchy (shay.banon)
|
||||||
|
@ -120,8 +119,6 @@ public class SourceLookup implements Map {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Pattern dotPattern = Pattern.compile("\\.");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values associated with the path. Those are "low" level values, and it can
|
* Returns the values associated with the path. Those are "low" level values, and it can
|
||||||
* handle path expression where an array/list is navigated within.
|
* handle path expression where an array/list is navigated within.
|
||||||
|
|
Loading…
Reference in New Issue