use of org.apache.lucene.document.StringField in project elasticsearch by elastic.
the class GeoFieldDataTests method fillSingleValueAllSet.
@Override
protected void fillSingleValueAllSet() throws Exception {
Document d = new Document();
d.add(new StringField("_id", "1", Field.Store.NO));
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "2", Field.Store.NO));
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "3", Field.Store.NO));
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
writer.addDocument(d);
}
use of org.apache.lucene.document.StringField in project elasticsearch by elastic.
the class GeoFieldDataTests method fillExtendedMvSet.
@Override
protected void fillExtendedMvSet() throws Exception {
Document d;
final int maxDocs = randomInt(10);
for (int i = 0; i < maxDocs; ++i) {
d = new Document();
d.add(new StringField("_id", i + "", Field.Store.NO));
int maxVals = randomInt(5);
for (int v = 0; v < maxVals; ++v) {
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
}
writer.addDocument(d);
if (randomBoolean()) {
writer.commit();
}
}
}
use of org.apache.lucene.document.StringField in project elasticsearch by elastic.
the class GeoFieldDataTests method fillMultiValueWithMissing.
@Override
protected void fillMultiValueWithMissing() throws Exception {
Document d = new Document();
d.add(new StringField("_id", "1", Field.Store.NO));
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
writer.addDocument(d);
// missing
d = new Document();
d.add(new StringField("_id", "2", Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "3", Field.Store.NO));
d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
writer.addDocument(d);
}
use of org.apache.lucene.document.StringField in project elasticsearch by elastic.
the class IndexFieldDataServiceTests method testFieldDataCacheListener.
public void testFieldDataCacheListener() throws Exception {
final IndexService indexService = createIndex("test");
final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
// copy the ifdService since we can set the listener only once.
final IndexFieldDataService ifdService = new IndexFieldDataService(indexService.getIndexSettings(), indicesService.getIndicesFieldDataCache(), indicesService.getCircuitBreakerService(), indexService.mapperService());
final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
final MappedFieldType mapper1 = new TextFieldMapper.Builder("s").fielddata(true).build(ctx).fieldType();
final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new KeywordAnalyzer()));
Document doc = new Document();
doc.add(new StringField("s", "thisisastring", Store.NO));
writer.addDocument(doc);
DirectoryReader open = DirectoryReader.open(writer);
final boolean wrap = randomBoolean();
final IndexReader reader = wrap ? ElasticsearchDirectoryReader.wrap(open, new ShardId("test", "_na_", 1)) : open;
final AtomicInteger onCacheCalled = new AtomicInteger();
final AtomicInteger onRemovalCalled = new AtomicInteger();
ifdService.setListener(new IndexFieldDataCache.Listener() {
@Override
public void onCache(ShardId shardId, String fieldName, Accountable ramUsage) {
if (wrap) {
assertEquals(new ShardId("test", "_na_", 1), shardId);
} else {
assertNull(shardId);
}
onCacheCalled.incrementAndGet();
}
@Override
public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, long sizeInBytes) {
if (wrap) {
assertEquals(new ShardId("test", "_na_", 1), shardId);
} else {
assertNull(shardId);
}
onRemovalCalled.incrementAndGet();
}
});
IndexFieldData<?> ifd = ifdService.getForField(mapper1);
LeafReaderContext leafReaderContext = reader.getContext().leaves().get(0);
AtomicFieldData load = ifd.load(leafReaderContext);
assertEquals(1, onCacheCalled.get());
assertEquals(0, onRemovalCalled.get());
reader.close();
load.close();
writer.close();
assertEquals(1, onCacheCalled.get());
assertEquals(1, onRemovalCalled.get());
ifdService.clear();
}
use of org.apache.lucene.document.StringField in project elasticsearch by elastic.
the class AbstractFieldDataTestCase method testEmpty.
public void testEmpty() throws Exception {
Document d = new Document();
d.add(new StringField("field", "value", Field.Store.NO));
writer.addDocument(d);
refreshReader();
IndexFieldData fieldData = getForField("non_existing_field");
int max = randomInt(7);
for (LeafReaderContext readerContext : readerContexts) {
AtomicFieldData previous = null;
for (int i = 0; i < max; i++) {
AtomicFieldData current = fieldData.load(readerContext);
assertThat(current.ramBytesUsed(), equalTo(0L));
if (previous != null) {
assertThat(current, not(sameInstance(previous)));
}
previous = current;
}
}
}
Aggregations