use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.text.Text in project elasticsearch by elastic.
the class BaseXContentTestCase method testText.
public void testText() throws Exception {
assertResult("{'text':null}", () -> builder().startObject().field("text", (Text) null).endObject());
assertResult("{'text':''}", () -> builder().startObject().field("text", new Text("")).endObject());
assertResult("{'text':'foo bar'}", () -> builder().startObject().field("text", new Text("foo bar")).endObject());
final BytesReference random = new BytesArray(randomBytes());
XContentBuilder builder = builder().startObject().field("text", new Text(random)).endObject();
XContentParser parser = createParser(xcontentType().xContent(), builder.bytes());
assertSame(parser.nextToken(), Token.START_OBJECT);
assertSame(parser.nextToken(), Token.FIELD_NAME);
assertEquals(parser.currentName(), "text");
assertTrue(parser.nextToken().isValue());
assertThat(parser.utf8Bytes().utf8ToString(), equalTo(random.utf8ToString()));
assertSame(parser.nextToken(), Token.END_OBJECT);
assertNull(parser.nextToken());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.text.Text in project elasticsearch by elastic.
the class BaseXContentTestCase method testObjects.
public void testObjects() throws Exception {
Map<String, Object[]> objects = new HashMap<>();
objects.put("{'objects':[false,true,false]}", new Object[] { false, true, false });
objects.put("{'objects':[1,1,2,3,5,8,13]}", new Object[] { (byte) 1, (byte) 1, (byte) 2, (byte) 3, (byte) 5, (byte) 8, (byte) 13 });
objects.put("{'objects':[1.0,1.0,2.0,3.0,5.0,8.0,13.0]}", new Object[] { 1.0d, 1.0d, 2.0d, 3.0d, 5.0d, 8.0d, 13.0d });
objects.put("{'objects':[1.0,1.0,2.0,3.0,5.0,8.0,13.0]}", new Object[] { 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 8.0f, 13.0f });
objects.put("{'objects':[{'lat':45.759429931640625,'lon':4.8394775390625}]}", new Object[] { GeoPoint.fromGeohash("u05kq4k") });
objects.put("{'objects':[1,1,2,3,5,8,13]}", new Object[] { 1, 1, 2, 3, 5, 8, 13 });
objects.put("{'objects':[1,1,2,3,5,8,13]}", new Object[] { 1L, 1L, 2L, 3L, 5L, 8L, 13L });
objects.put("{'objects':[1,1,2,3,5,8]}", new Object[] { (short) 1, (short) 1, (short) 2, (short) 3, (short) 5, (short) 8 });
objects.put("{'objects':['a','b','c']}", new Object[] { "a", "b", "c" });
objects.put("{'objects':['a','b','c']}", new Object[] { new Text("a"), new Text(new BytesArray("b")), new Text("c") });
objects.put("{'objects':null}", null);
objects.put("{'objects':[null,null,null]}", new Object[] { null, null, null });
objects.put("{'objects':['OPEN','CLOSE']}", IndexMetaData.State.values());
objects.put("{'objects':[{'f1':'v1'},{'f2':'v2'}]}", new Object[] { singletonMap("f1", "v1"), singletonMap("f2", "v2") });
objects.put("{'objects':[[1,2,3],[4,5]]}", new Object[] { Arrays.asList(1, 2, 3), Arrays.asList(4, 5) });
final String paths = Constants.WINDOWS ? "{'objects':['a\\\\b\\\\c','d\\\\e']}" : "{'objects':['a/b/c','d/e']}";
objects.put(paths, new Object[] { PathUtils.get("a", "b", "c"), PathUtils.get("d", "e") });
final DateTimeFormatter formatter = XContentBuilder.DEFAULT_DATE_PRINTER;
final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
final Date d2 = new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
objects.put("{'objects':['" + formatter.print(d1.getTime()) + "','" + formatter.print(d2.getTime()) + "']}", new Object[] { d1, d2 });
final DateTime dt1 = DateTime.now();
final DateTime dt2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC);
objects.put("{'objects':['" + formatter.print(dt1) + "','2016-12-25T07:59:42.213Z']}", new Object[] { dt1, dt2 });
final Calendar c1 = new DateTime(2012, 7, 7, 10, 23, DateTimeZone.UTC).toCalendar(Locale.ROOT);
final Calendar c2 = new DateTime(2014, 11, 16, 19, 36, DateTimeZone.UTC).toCalendar(Locale.ROOT);
objects.put("{'objects':['2012-07-07T10:23:00.000Z','2014-11-16T19:36:00.000Z']}", new Object[] { c1, c2 });
final ToXContent x1 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", 2).array("f3", 3, 4, 5).endObject();
final ToXContent x2 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", x1).endObject();
objects.put("{'objects':[{'f1':'v1','f2':2,'f3':[3,4,5]},{'f1':'v1','f2':{'f1':'v1','f2':2,'f3':[3,4,5]}}]}", new Object[] { x1, x2 });
for (Map.Entry<String, Object[]> o : objects.entrySet()) {
final String expected = o.getKey();
assertResult(expected, () -> builder().startObject().field("objects", o.getValue()).endObject());
assertResult(expected, () -> builder().startObject().field("objects").value(o.getValue()).endObject());
assertResult(expected, () -> builder().startObject().field("objects").values(o.getValue()).endObject());
assertResult(expected, () -> builder().startObject().array("objects", o.getValue()).endObject());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.text.Text in project elasticsearch by elastic.
the class SearchHitTests method testNullSource.
public void testNullSource() throws Exception {
SearchHit searchHit = new SearchHit(0, "_id", new Text("_type"), null);
assertThat(searchHit.getSourceAsMap(), nullValue());
assertThat(searchHit.getSourceRef(), nullValue());
assertThat(searchHit.getSourceAsMap(), nullValue());
assertThat(searchHit.getSourceAsString(), nullValue());
assertThat(searchHit.getSourceAsMap(), nullValue());
assertThat(searchHit.getSourceRef(), nullValue());
assertThat(searchHit.getSourceAsString(), nullValue());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.text.Text in project elasticsearch by elastic.
the class InternalTopHitsTests method createTestInstance.
@Override
protected InternalTopHits createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
int from = 0;
int requestedSize = between(1, 40);
int actualSize = between(0, requestedSize);
float maxScore = Float.MIN_VALUE;
ScoreDoc[] scoreDocs = new ScoreDoc[actualSize];
SearchHit[] hits = new SearchHit[actualSize];
Set<Integer> usedDocIds = new HashSet<>();
for (int i = 0; i < actualSize; i++) {
float score = randomFloat();
maxScore = max(maxScore, score);
int docId = randomValueOtherThanMany(usedDocIds::contains, () -> between(0, IndexWriter.MAX_DOCS));
usedDocIds.add(docId);
Map<String, SearchHitField> searchHitFields = new HashMap<>();
if (testInstancesLookSortedByField) {
Object[] fields = new Object[testInstancesSortFields.length];
for (int f = 0; f < testInstancesSortFields.length; f++) {
fields[f] = randomOfType(testInstancesSortFields[f].getType());
}
scoreDocs[i] = new FieldDoc(docId, score, fields);
} else {
scoreDocs[i] = new ScoreDoc(docId, score);
}
hits[i] = new SearchHit(docId, Integer.toString(i), new Text("test"), searchHitFields);
hits[i].score(score);
}
int totalHits = between(actualSize, 500000);
SearchHits searchHits = new SearchHits(hits, totalHits, maxScore);
TopDocs topDocs;
Arrays.sort(scoreDocs, scoreDocComparator());
if (testInstancesLookSortedByField) {
topDocs = new TopFieldDocs(totalHits, scoreDocs, testInstancesSortFields, maxScore);
} else {
topDocs = new TopDocs(totalHits, scoreDocs, maxScore);
}
return new InternalTopHits(name, from, requestedSize, topDocs, searchHits, pipelineAggregators, metaData);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.text.Text in project hazelcast by hazelcast.
the class ElasticSourcePTest method givenMultipleResults_when_runProcessor_then_useScrollIdInFollowupScrollRequest.
@Test
public void givenMultipleResults_when_runProcessor_then_useScrollIdInFollowupScrollRequest() throws Exception {
SearchHit hit = new SearchHit(0, "id-0", new Text("ignored"), emptyMap(), emptyMap());
hit.sourceRef(new BytesArray(HIT_SOURCE));
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit }, new TotalHits(3, EQUAL_TO), Float.NaN));
SearchResponse response2 = mock(SearchResponse.class);
SearchHit hit2 = new SearchHit(1, "id-1", new Text("ignored"), emptyMap(), emptyMap());
hit2.sourceRef(new BytesArray(HIT_SOURCE2));
when(response2.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit2 }, new TotalHits(3, EQUAL_TO), Float.NaN));
SearchResponse response3 = mock(SearchResponse.class);
when(response3.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(3, EQUAL_TO), Float.NaN));
when(mockClient.scroll(any(), any())).thenReturn(response2, response3);
TestSupport testSupport = runProcessor();
testSupport.expectOutput(newArrayList(HIT_SOURCE, HIT_SOURCE2));
ArgumentCaptor<SearchScrollRequest> captor = forClass(SearchScrollRequest.class);
verify(mockClient, times(2)).scroll(captor.capture(), any());
SearchScrollRequest request = captor.getValue();
assertThat(request.scrollId()).isEqualTo(SCROLL_ID);
assertThat(request.scroll().keepAlive().getStringRep()).isEqualTo(KEEP_ALIVE);
}
Aggregations