private static String resolveIndexName(String fieldName, QueryShardContext context) { MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType != null) { return fieldType.names().indexName(); } return fieldName; }
@Override protected SpanQuery doToQuery(QueryShardContext context) throws IOException { String fieldInQuery = fieldName; MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType != null) { fieldInQuery = fieldType.name(); } Query innerQuery = queryBuilder.toQuery(context); assert innerQuery instanceof SpanQuery; return new FieldMaskingSpanQuery((SpanQuery) innerQuery, fieldInQuery); }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType == null) { throw new QueryShardException( context, "failed to parse [{}] query. missing [{}] field [{}]", NAME, BaseGeoPointFieldMapper.CONTENT_TYPE, fieldName); } if (!(fieldType instanceof BaseGeoPointFieldMapper.GeoPointFieldType)) { throw new QueryShardException( context, "failed to parse [{}] query. field [{}] is not a geo_point field", NAME, fieldName); } BaseGeoPointFieldMapper.GeoPointFieldType geoFieldType = ((BaseGeoPointFieldMapper.GeoPointFieldType) fieldType); if (!geoFieldType.isGeoHashPrefixEnabled()) { throw new QueryShardException( context, "failed to parse [{}] query. [geohash_prefix] is not enabled for field [{}]", NAME, fieldName); } String geohash = this.geohash; if (levels != null) { int len = Math.min(levels, geohash.length()); geohash = geohash.substring(0, len); } Query query; if (neighbors) { query = create( context, geoFieldType, geohash, GeoHashUtils.addNeighbors(geohash, new ArrayList<CharSequence>(8))); } else { query = create(context, geoFieldType, geohash, null); } return query; }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { String field; MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType != null) { field = fieldType.names().indexName(); } else { field = fieldName; } Analyzer analyzerObj; if (analyzer == null) { if (fieldType != null) { analyzerObj = context.getSearchAnalyzer(fieldType); } else { analyzerObj = context.getMapperService().searchAnalyzer(); } } else { analyzerObj = context.getMapperService().analysisService().analyzer(analyzer); if (analyzerObj == null) { throw new QueryShardException(context, "[common] analyzer [" + analyzer + "] not found"); } } Occur highFreqOccur = highFreqOperator.toBooleanClauseOccur(); Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur(); ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery( highFreqOccur, lowFreqOccur, cutoffFrequency, disableCoord, fieldType); return parseQueryString( commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); }
@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 (context.indexVersionCreated().before(Version.V_2_2_0)) { if (queryBuilder.type() == GeoExecType.INDEXED) { assertTrue("Found no indexed geo query.", query instanceof ConstantScoreQuery); } else { assertTrue( "Found no indexed geo query.", query instanceof LegacyInMemoryGeoBoundingBoxQuery); } } else if (context.indexVersionCreated().before(Version.V_5_0_0_beta1)) { assertTrue("Found no indexed geo query.", query instanceof GeoPointInBBoxQuery); } else { assertTrue("Found no indexed geo query.", query instanceof Query); } } }