use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class FieldMapper method parse.
/**
* Parse using the provided {@link ParseContext} and return a mapping
* update if dynamic mappings modified the mappings, or {@code null} if
* mappings were not modified.
*/
public Mapper parse(ParseContext context) throws IOException {
final List<IndexableField> fields = new ArrayList<>(2);
try {
parseCreateField(context, fields);
for (IndexableField field : fields) {
if (!customBoost() && // don't set boosts eg. on dv fields
field.fieldType().indexOptions() != IndexOptions.NONE && indexCreatedVersion.before(Version.V_5_0_0_alpha1)) {
((Field) (field)).setBoost(fieldType().boost());
}
context.doc().add(field);
}
} catch (Exception e) {
throw new MapperParsingException("failed to parse [" + fieldType().name() + "]", e);
}
multiFields.parse(this, context);
return null;
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class UidFieldMapper method parseCreateField.
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
Field uid = new Field(NAME, Uid.createUid(context.sourceToParse().type(), context.sourceToParse().id()), Defaults.FIELD_TYPE);
fields.add(uid);
if (fieldType().hasDocValues()) {
fields.add(new BinaryDocValuesField(NAME, new BytesRef(uid.stringValue())));
}
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class VersionFieldMapper method parseCreateField.
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
// see InternalEngine.updateVersion to see where the real version value is set
final Field version = new NumericDocValuesField(NAME, -1L);
context.version(version);
fields.add(version);
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class CategoryContextMapping method parseContext.
@Override
public Set<CharSequence> parseContext(Document document) {
Set<CharSequence> values = null;
if (fieldName != null) {
IndexableField[] fields = document.getFields(fieldName);
values = new HashSet<>(fields.length);
for (IndexableField field : fields) {
values.add(field.stringValue());
}
}
return (values == null) ? Collections.<CharSequence>emptySet() : values;
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class CategoryContextMappingTests method testIndexingWithMultipleContexts.
public void testIndexingWithMultipleContexts() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().startObject().field("name", "type").field("type", "category").endObject().endArray().endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
MappedFieldType completionFieldType = fieldMapper.fieldType();
XContentBuilder builder = jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").field("weight", 5).startObject("contexts").array("ctx", "ctx1", "ctx2", "ctx3").array("type", "typr3", "ftg").endObject().endObject().endArray().endObject();
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", builder.bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertContextSuggestFields(fields, 3);
}
Aggregations