use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.
the class GeoDistanceSortBuilderTests method provideMappedFieldType.
@Override
protected MappedFieldType provideMappedFieldType(String name) {
MappedFieldType clone = GeoPointFieldMapper.Defaults.FIELD_TYPE.clone();
clone.setName(name);
return clone;
}
use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.
the class TextFieldTypeTests method testTermsQuery.
public void testTermsQuery() {
MappedFieldType ft = createDefaultFieldType();
ft.setName("field");
ft.setIndexOptions(IndexOptions.DOCS);
List<BytesRef> terms = new ArrayList<>();
terms.add(new BytesRef("foo"));
terms.add(new BytesRef("bar"));
assertEquals(new TermInSetQuery("field", terms), ft.termsQuery(Arrays.asList("foo", "bar"), null));
ft.setIndexOptions(IndexOptions.NONE);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.termsQuery(Arrays.asList("foo", "bar"), null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.
the class TextFieldTypeTests method testRegexpQuery.
public void testRegexpQuery() {
MappedFieldType ft = createDefaultFieldType();
ft.setName("field");
ft.setIndexOptions(IndexOptions.DOCS);
assertEquals(new RegexpQuery(new Term("field", "foo.*")), ft.regexpQuery("foo.*", 0, 10, null, null));
ft.setIndexOptions(IndexOptions.NONE);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.regexpQuery("foo.*", 0, 10, null, null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.
the class TextFieldTypeTests method testTermQuery.
public void testTermQuery() {
MappedFieldType ft = createDefaultFieldType();
ft.setName("field");
ft.setIndexOptions(IndexOptions.DOCS);
assertEquals(new TermQuery(new Term("field", "foo")), ft.termQuery("foo", null));
ft.setIndexOptions(IndexOptions.NONE);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.termQuery("bar", null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.
the class GeoBoundingBoxQueryBuilderTests method doAssertLuceneQuery.
@Override
protected void doAssertLuceneQuery(GeoBoundingBoxQueryBuilder queryBuilder, Query query, SearchContext searchContext) throws IOException {
QueryShardContext context = searchContext.getQueryShardContext();
MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName());
if (fieldType == null) {
assertTrue("Found no indexed geo query.", query instanceof MatchNoDocsQuery);
} else if (query instanceof IndexOrDocValuesQuery) {
// TODO: remove the if statement once we always use LatLonPoint
Query indexQuery = ((IndexOrDocValuesQuery) query).getIndexQuery();
assertEquals(LatLonPoint.newBoxQuery(queryBuilder.fieldName(), queryBuilder.bottomRight().lat(), queryBuilder.topLeft().lat(), queryBuilder.topLeft().lon(), queryBuilder.bottomRight().lon()), indexQuery);
Query dvQuery = ((IndexOrDocValuesQuery) query).getRandomAccessQuery();
assertEquals(LatLonDocValuesField.newBoxQuery(queryBuilder.fieldName(), queryBuilder.bottomRight().lat(), queryBuilder.topLeft().lat(), queryBuilder.topLeft().lon(), queryBuilder.bottomRight().lon()), dvQuery);
}
}
Aggregations