Java 类org.apache.lucene.index.DocValuesType 实例源码

项目:elasticsearch_my    文件:KeywordFieldMapperTests.java   
public void testDisableIndex() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "keyword").field("index", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "1234")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    assertEquals(IndexOptions.NONE, fields[0].fieldType().indexOptions());
    assertEquals(DocValuesType.SORTED_SET, fields[0].fieldType().docValuesType());
}
项目:elasticsearch_my    文件:KeywordFieldMapperTests.java   
public void testDisableDocValues() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "keyword").field("doc_values", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "1234")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    assertEquals(DocValuesType.NONE, fields[0].fieldType().docValuesType());
}
项目:elasticsearch_my    文件:ScaledFloatFieldMapperTests.java   
public void testNotIndexed() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "scaled_float")
            .field("index", false).field("scaling_factor", 10.0).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", 123)
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    IndexableField dvField = fields[0];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    assertEquals(1230, dvField.numericValue().longValue());
}
项目:elasticsearch_my    文件:DateFieldMapperTests.java   
public void testNotIndexed() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "date").field("index", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "2016-03-11")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    IndexableField dvField = fields[0];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
}
项目:elasticsearch_my    文件:DateFieldMapperTests.java   
public void testStore() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "date").field("store", true).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "2016-03-11")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(3, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    IndexableField storedField = fields[2];
    assertTrue(storedField.fieldType().stored());
    assertEquals(1457654400000L, storedField.numericValue().longValue());
}
项目:elasticsearch_my    文件:NumberFieldMapperTests.java   
@Override
public void doTestDefaults(String type) throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", type).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", 123)
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertFalse(pointField.fieldType().stored());
    assertEquals(123, pointField.numericValue().doubleValue(), 0d);
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    assertFalse(dvField.fieldType().stored());
}
项目:elasticsearch_my    文件:NumberFieldMapperTests.java   
@Override
public void doTestNotIndexed(String type) throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", type).field("index", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", 123)
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    IndexableField dvField = fields[0];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
}
项目:elasticsearch_my    文件:IpFieldMapperTests.java   
public void testNotIndexed() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "ip").field("index", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "::1")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    IndexableField dvField = fields[0];
    assertEquals(DocValuesType.SORTED_SET, dvField.fieldType().docValuesType());
}
项目:elasticsearch_my    文件:IpFieldMapperTests.java   
public void testStore() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "ip").field("store", true).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "::1")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(3, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_SET, dvField.fieldType().docValuesType());
    IndexableField storedField = fields[2];
    assertTrue(storedField.fieldType().stored());
    assertEquals(new BytesRef(InetAddressPoint.encode(InetAddress.getByName("::1"))),
            storedField.binaryValue());
}
项目:Elasticsearch    文件:VersionFieldUpgrader.java   
static CodecReader wrap(CodecReader reader) throws IOException {
    final FieldInfos fieldInfos = reader.getFieldInfos();
    final FieldInfo versionInfo = fieldInfos.fieldInfo(VersionFieldMapper.NAME);
    if (versionInfo != null && versionInfo.getDocValuesType() != DocValuesType.NONE) {
        // the reader is a recent one, it has versions and they are stored
        // in a numeric doc values field
        return reader;
    }
    // The segment is an old one, look at the _uid field
    final Terms terms = reader.terms(UidFieldMapper.NAME);
    if (terms == null || !terms.hasPayloads()) {
        // The segment doesn't have an _uid field or doesn't have payloads
        // don't try to do anything clever. If any other segment has versions
        // all versions of this segment will be initialized to 0
        return reader;
    }
    // convert _uid payloads -> _version docvalues
    return new VersionFieldUpgrader(reader);
}
项目:Elasticsearch    文件:ParentFieldMapper.java   
@Override
public ParentFieldMapper build(BuilderContext context) {
    if (parentType == null) {
        throw new MapperParsingException("[_parent] field mapping must contain the [type] option");
    }
    parentJoinFieldType.setNames(new MappedFieldType.Names(joinField(documentType)));
    parentJoinFieldType.setFieldDataType(null);
    childJoinFieldType.setNames(new MappedFieldType.Names(joinField(parentType)));
    if (context.indexCreatedVersion().before(Version.V_2_0_0_beta1)) {
        childJoinFieldType.setHasDocValues(false);
        childJoinFieldType.setDocValuesType(DocValuesType.NONE);
        parentJoinFieldType.setHasDocValues(false);
        parentJoinFieldType.setDocValuesType(DocValuesType.NONE);
    }
    return new ParentFieldMapper(fieldType, parentJoinFieldType, childJoinFieldType, parentType, context.indexSettings());
}
项目:neo4j-lucene5-index    文件:DocValuesCollector.java   
/**
 * @return the {@code NumericDocValues} for a given field
 * @throws IllegalArgumentException if this field is not indexed with numeric doc values
 */
public NumericDocValues readDocValues( String field )
{
    try
    {
        NumericDocValues dv = context.reader().getNumericDocValues( field );
        if ( dv == null )
        {
            FieldInfo fi = context.reader().getFieldInfos().fieldInfo( field );
            DocValuesType actual = null;
            if ( fi != null )
            {
                actual = fi.getDocValuesType();
            }
            throw new IllegalStateException(
                    "The field '" + field + "' is not indexed properly, expected NumericDV, but got '" +
                    actual + "'" );
        }
        return dv;
    }
    catch ( IOException e )
    {
        throw new RuntimeException( e );
    }
}
项目:clue    文件:DocValCommand.java   
private Object readDocValues(String field, DocValuesType docValType, LeafReader atomicReader) throws IOException{
  Object docVals = null;
  if (docValType == DocValuesType.NUMERIC) {
    docVals = atomicReader.getNumericDocValues(field);
  }
  else if (docValType == DocValuesType.BINARY) {
    docVals = atomicReader.getBinaryDocValues(field);
  }
  else if (docValType == DocValuesType.SORTED) {
    docVals = atomicReader.getSortedDocValues(field);
  }
  else if (docValType == DocValuesType.SORTED_NUMERIC) {
    docVals = atomicReader.getSortedNumericDocValues(field);
  }
  else if (docValType == DocValuesType.SORTED_SET) {
    docVals = atomicReader.getSortedSetDocValues(field);
  }
  return docVals;
}
项目:clue    文件:DocValCommand.java   
private void showDocId(int docid, int docBase, String field,
    LeafReader atomicReader, PrintStream out, int segmentid)
    throws Exception {
  FieldInfo finfo = atomicReader.getFieldInfos().fieldInfo(field);

  if (finfo == null || finfo.getDocValuesType() == DocValuesType.NONE) {
    out.println("docvalue does not exist for field: " + field);
    return;
  }


  DocValuesType docValType = finfo.getDocValuesType();
  BytesRef bref = new BytesRef();

  showDocId(docid, docBase, readDocValues(field, docValType, atomicReader), docValType, bref, out, segmentid);
}
项目:elasticsearch_my    文件:PercolatorFieldMapper.java   
static BinaryFieldMapper createQueryBuilderFieldBuilder(BuilderContext context) {
    BinaryFieldMapper.Builder builder = new BinaryFieldMapper.Builder(QUERY_BUILDER_FIELD_NAME);
    builder.docValues(true);
    builder.indexOptions(IndexOptions.NONE);
    builder.store(false);
    builder.fieldType().setDocValuesType(DocValuesType.BINARY);
    return builder.build(context);
}
项目:elasticsearch_my    文件:CollapsingDocValuesSource.java   
private static DocValuesType getDocValuesType(LeafReader in, String field) {
    FieldInfo fi = in.getFieldInfos().fieldInfo(field);
    if (fi != null) {
        return fi.getDocValuesType();
    }
    return null;
}
项目:elasticsearch_my    文件:AbstractLatLonPointDVIndexFieldData.java   
/** helper: checks a fieldinfo and throws exception if its definitely not a LatLonDocValuesField */
static void checkCompatible(FieldInfo fieldInfo) {
    // dv properties could be "unset", if you e.g. used only StoredField with this same name in the segment.
    if (fieldInfo.getDocValuesType() != DocValuesType.NONE
        && fieldInfo.getDocValuesType() != LatLonDocValuesField.TYPE.docValuesType()) {
        throw new IllegalArgumentException("field=\"" + fieldInfo.name + "\" was indexed with docValuesType="
            + fieldInfo.getDocValuesType() + " but this type has docValuesType="
            + LatLonDocValuesField.TYPE.docValuesType() + ", is the field really a LatLonDocValuesField?");
    }
}
项目:elasticsearch_my    文件:ParentFieldMapper.java   
static KeywordFieldMapper createParentJoinFieldMapper(String docType, BuilderContext context) {
    KeywordFieldMapper.Builder parentJoinField = new KeywordFieldMapper.Builder(joinField(docType));
    parentJoinField.indexOptions(IndexOptions.NONE);
    parentJoinField.docValues(true);
    parentJoinField.fieldType().setDocValuesType(DocValuesType.SORTED);
    return parentJoinField.build(context);
}
项目:elasticsearch_my    文件:KeywordFieldMapperTests.java   
public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "keyword").endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "1234")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);

    assertEquals(new BytesRef("1234"), fields[0].binaryValue());
    IndexableFieldType fieldType = fields[0].fieldType();
    assertThat(fieldType.omitNorms(), equalTo(true));
    assertFalse(fieldType.tokenized());
    assertFalse(fieldType.stored());
    assertThat(fieldType.indexOptions(), equalTo(IndexOptions.DOCS));
    assertThat(fieldType.storeTermVectors(), equalTo(false));
    assertThat(fieldType.storeTermVectorOffsets(), equalTo(false));
    assertThat(fieldType.storeTermVectorPositions(), equalTo(false));
    assertThat(fieldType.storeTermVectorPayloads(), equalTo(false));
    assertEquals(DocValuesType.NONE, fieldType.docValuesType());

    assertEquals(new BytesRef("1234"), fields[1].binaryValue());
    fieldType = fields[1].fieldType();
    assertThat(fieldType.indexOptions(), equalTo(IndexOptions.NONE));
    assertEquals(DocValuesType.SORTED_SET, fieldType.docValuesType());
}
项目:elasticsearch_my    文件:KeywordFieldMapperTests.java   
public void testNormalizer() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field")
            .field("type", "keyword").field("normalizer", "my_lowercase").endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "AbC")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);

    assertEquals(new BytesRef("abc"), fields[0].binaryValue());
    IndexableFieldType fieldType = fields[0].fieldType();
    assertThat(fieldType.omitNorms(), equalTo(true));
    assertFalse(fieldType.tokenized());
    assertFalse(fieldType.stored());
    assertThat(fieldType.indexOptions(), equalTo(IndexOptions.DOCS));
    assertThat(fieldType.storeTermVectors(), equalTo(false));
    assertThat(fieldType.storeTermVectorOffsets(), equalTo(false));
    assertThat(fieldType.storeTermVectorPositions(), equalTo(false));
    assertThat(fieldType.storeTermVectorPayloads(), equalTo(false));
    assertEquals(DocValuesType.NONE, fieldType.docValuesType());

    assertEquals(new BytesRef("abc"), fields[1].binaryValue());
    fieldType = fields[1].fieldType();
    assertThat(fieldType.indexOptions(), equalTo(IndexOptions.NONE));
    assertEquals(DocValuesType.SORTED_SET, fieldType.docValuesType());
}
项目:elasticsearch_my    文件:ScaledFloatFieldMapperTests.java   
public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "scaled_float")
            .field("scaling_factor", 10.0).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", 123)
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertFalse(pointField.fieldType().stored());
    assertEquals(1230, pointField.numericValue().longValue());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    assertEquals(1230, dvField.numericValue().longValue());
    assertFalse(dvField.fieldType().stored());
}
项目:elasticsearch_my    文件:ScaledFloatFieldMapperTests.java   
public void testStore() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "scaled_float")
            .field("store", true).field("scaling_factor", 10.0).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", 123)
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(3, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(1230, pointField.numericValue().doubleValue(), 0d);
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    IndexableField storedField = fields[2];
    assertTrue(storedField.fieldType().stored());
    assertEquals(1230, storedField.numericValue().longValue());
}
项目:elasticsearch_my    文件:DateFieldMapperTests.java   
public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "date").endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "2016-03-11")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(8, pointField.fieldType().pointNumBytes());
    assertFalse(pointField.fieldType().stored());
    assertEquals(1457654400000L, pointField.numericValue().longValue());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    assertEquals(1457654400000L, dvField.numericValue().longValue());
    assertFalse(dvField.fieldType().stored());
}
项目:elasticsearch_my    文件:TextFieldMapperTests.java   
public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "text").endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "1234")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);

    assertEquals("1234", fields[0].stringValue());
    IndexableFieldType fieldType = fields[0].fieldType();
    assertThat(fieldType.omitNorms(), equalTo(false));
    assertTrue(fieldType.tokenized());
    assertFalse(fieldType.stored());
    assertThat(fieldType.indexOptions(), equalTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS));
    assertThat(fieldType.storeTermVectors(), equalTo(false));
    assertThat(fieldType.storeTermVectorOffsets(), equalTo(false));
    assertThat(fieldType.storeTermVectorPositions(), equalTo(false));
    assertThat(fieldType.storeTermVectorPayloads(), equalTo(false));
    assertEquals(DocValuesType.NONE, fieldType.docValuesType());
}
项目:elasticsearch_my    文件:NumberFieldMapperTests.java   
@Override
public void doTestStore(String type) throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", type).field("store", true).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", 123)
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(3, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(123, pointField.numericValue().doubleValue(), 0d);
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    IndexableField storedField = fields[2];
    assertTrue(storedField.fieldType().stored());
    assertEquals(123, storedField.numericValue().doubleValue(), 0d);
}
项目:elasticsearch_my    文件:NumberFieldMapperTests.java   
@Override
public void doTestCoerce(String type) throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", type).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "123")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(123, pointField.numericValue().doubleValue(), 0d);
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());

    mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", type).field("coerce", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper2.mappingSource().toString());

    ThrowingRunnable runnable = () -> mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "123")
            .endObject()
            .bytes());
    MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
    assertThat(e.getCause().getMessage(), containsString("passed as String"));
}
项目:elasticsearch_my    文件:IpFieldMapperTests.java   
public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "ip").endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "::1")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(16, pointField.fieldType().pointNumBytes());
    assertFalse(pointField.fieldType().stored());
    assertEquals(new BytesRef(InetAddressPoint.encode(InetAddresses.forString("::1"))), pointField.binaryValue());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_SET, dvField.fieldType().docValuesType());
    assertEquals(new BytesRef(InetAddressPoint.encode(InetAddresses.forString("::1"))), dvField.binaryValue());
    assertFalse(dvField.fieldType().stored());
}
项目:elasticsearch_my    文件:BooleanFieldMapperTests.java   
public void testDocValues() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties")
            .startObject("bool1")
                .field("type", "boolean")
            .endObject()
            .startObject("bool2")
                .field("type", "boolean")
                .field("index", false)
            .endObject()
            .startObject("bool3")
                .field("type", "boolean")
                .field("index", true)
            .endObject()
            .endObject()
            .endObject().endObject().string();

    DocumentMapper defaultMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));

    ParsedDocument parsedDoc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("bool1", true)
            .field("bool2", true)
            .field("bool3", true)
            .endObject()
            .bytes());
    Document doc = parsedDoc.rootDoc();
    IndexableField[] fields = doc.getFields("bool1");
    assertEquals(2, fields.length);
    assertEquals(DocValuesType.NONE, fields[0].fieldType().docValuesType());
    assertEquals(DocValuesType.SORTED_NUMERIC, fields[1].fieldType().docValuesType());
    fields = doc.getFields("bool2");
    assertEquals(1, fields.length);
    assertEquals(DocValuesType.SORTED_NUMERIC, fields[0].fieldType().docValuesType());
    fields = doc.getFields("bool3");
    assertEquals(DocValuesType.NONE, fields[0].fieldType().docValuesType());
    assertEquals(DocValuesType.SORTED_NUMERIC, fields[1].fieldType().docValuesType());
}
项目:Elasticsearch    文件:VersionFieldUpgrader.java   
VersionFieldUpgrader(CodecReader in) {
    super(in);

    // Find a free field number
    int fieldNumber = 0;
    for (FieldInfo fi : in.getFieldInfos()) {
        fieldNumber = Math.max(fieldNumber, fi.number + 1);
    }

    // TODO: lots of things can wrong here...
    FieldInfo newInfo = new FieldInfo(VersionFieldMapper.NAME,               // field name
                                      fieldNumber,                           // field number
                                      false,                                 // store term vectors
                                      false,                                 // omit norms
                                      false,                                 // store payloads
                                      IndexOptions.NONE,                     // index options
                                      DocValuesType.NUMERIC,                 // docvalues
                                      -1,                                    // docvalues generation
                                      Collections.<String, String>emptyMap() // attributes
                                      );
    newInfo.checkConsistency(); // fail merge immediately if above code is wrong

    final ArrayList<FieldInfo> fieldInfoList = new ArrayList<>();
    for (FieldInfo info : in.getFieldInfos()) {
        if (!info.name.equals(VersionFieldMapper.NAME)) {
            fieldInfoList.add(info);
        }
    }
    fieldInfoList.add(newInfo);
    infos = new FieldInfos(fieldInfoList.toArray(new FieldInfo[fieldInfoList.size()]));
}
项目:Elasticsearch    文件:ParentFieldMapper.java   
private static MappedFieldType joinFieldTypeForParentType(String parentType, Settings indexSettings) {
    MappedFieldType parentJoinFieldType = Defaults.JOIN_FIELD_TYPE.clone();
    parentJoinFieldType.setNames(new MappedFieldType.Names(joinField(parentType)));

    Version indexCreated = Version.indexCreated(indexSettings);
    if (indexCreated.before(Version.V_2_0_0_beta1)) {
        parentJoinFieldType.setHasDocValues(false);
        parentJoinFieldType.setDocValuesType(DocValuesType.NONE);
    }
    parentJoinFieldType.freeze();
    return parentJoinFieldType;
}
项目:NGB-master    文件:SortedFloatPoint.java   
private static FieldType getType(int numDims) {
    FieldType type = new FieldType();
    type.setDimensions(numDims, Float.BYTES);
    type.setDocValuesType(DocValuesType.NUMERIC);
    type.freeze();
    return type;
}
项目:NGB-master    文件:SortedIntPoint.java   
private static FieldType getType(int numDims) {
    FieldType type = new FieldType();
    type.setDocValuesType(DocValuesType.NUMERIC);
    type.setDimensions(numDims, Integer.BYTES);
    type.freeze();
    return type;
}
项目:NGB    文件:SortedFloatPoint.java   
private static FieldType getType(int numDims) {
    FieldType type = new FieldType();
    type.setDimensions(numDims, Float.BYTES);
    type.setDocValuesType(DocValuesType.NUMERIC);
    type.freeze();
    return type;
}
项目:NGB    文件:SortedIntPoint.java   
private static FieldType getType(int numDims) {
    FieldType type = new FieldType();
    type.setDocValuesType(DocValuesType.NUMERIC);
    type.setDimensions(numDims, Integer.BYTES);
    type.freeze();
    return type;
}
项目:meresco-lucene    文件:DocumentStringToDocumentTest.java   
@Test
public void testSortedStringField() {
    JsonArray json = Json.createArrayBuilder()
            .add(Json.createObjectBuilder()
                .add("type", "StringField")
                .add("name", "name")
                .add("value", "value")
                .add("sort", JsonValue.TRUE))
            .build();
    Document result = convert(json.toString());
    assertEquals(DocValuesType.SORTED, result.getField("name").fieldType().docValuesType());
    assertEquals(new BytesRef("value"), result.getField("name").binaryValue());
}
项目:meresco-lucene    文件:DocumentStringToDocumentTest.java   
@Test
public void testSortedIntField() {
    JsonArray json = Json.createArrayBuilder()
            .add(Json.createObjectBuilder()
                .add("type", "IntField")
                .add("name", "name")
                .add("value", 1)
                .add("sort", JsonValue.TRUE))
            .build();
    Document result = convert(json.toString());
    assertEquals(DocValuesType.NUMERIC, result.getField("name").fieldType().docValuesType());
    assertEquals(1, result.getField("name").numericValue().intValue());
}
项目:meresco-lucene    文件:DocumentStringToDocumentTest.java   
@Test
public void testSortedLongField() {
    JsonArray json = Json.createArrayBuilder()
            .add(Json.createObjectBuilder()
                .add("type", "LongField")
                .add("name", "name")
                .add("value", 1L)
                .add("sort", JsonValue.TRUE))
            .build();
    Document result = convert(json.toString());
    assertEquals(DocValuesType.NUMERIC, result.getField("name").fieldType().docValuesType());
    assertEquals(1L, result.getField("name").numericValue().longValue());
}
项目:meresco-lucene    文件:DocumentStringToDocumentTest.java   
@Test
public void testSortedDoubleField() {
    JsonArray json = Json.createArrayBuilder()
            .add(Json.createObjectBuilder()
                .add("type", "DoubleField")
                .add("name", "name")
                .add("value", 1.5D)
                .add("sort", JsonValue.TRUE))
            .build();
    Document result = convert(json.toString());
    assertEquals(DocValuesType.NUMERIC, result.getField("name").fieldType().docValuesType());
    assertEquals(NumericUtils.doubleToSortableLong(1.5D), result.getField("name").numericValue().longValue());
}
项目:elasticsearch_my    文件:PercolatorFieldMapper.java   
public FieldType() {
    setIndexOptions(IndexOptions.NONE);
    setDocValuesType(DocValuesType.NONE);
    setStored(false);
}
项目:elasticsearch_my    文件:ScaledFloatFieldMapperTests.java   
public void testCoerce() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "scaled_float")
            .field("scaling_factor", 10.0).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper.mappingSource().toString());

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "123")
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(1230, pointField.numericValue().longValue());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());

    mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "scaled_float")
            .field("scaling_factor", 10.0).field("coerce", false).endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));

    assertEquals(mapping, mapper2.mappingSource().toString());

    ThrowingRunnable runnable = () -> mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
            .field("field", "123")
            .endObject()
            .bytes());
    MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
    assertThat(e.getCause().getMessage(), containsString("passed as String"));
}