@Override public Query termQuery(Object value, QueryShardContext context) { failIfNotIndexed(); TermQuery query = new TermQuery(new Term(name(), indexedValueForSearch(value))); if (boost() == 1f || (context != null && context.indexVersionCreated().before(Version.V_5_0_0_alpha1))) { return query; } return new BoostQuery(query, boost()); }
String id = uidString.substring(expectedPrefix.length(), uidString.length()); BytesRef encodedId; if (context.indexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { encodedId = Uid.encodeId(id); } else {
if (context.getMapperService().hasNested()) { return Queries.newNonNestedFilter(context.indexVersionCreated()); } else { return new MatchAllDocsQuery();
@Override public Query termsQuery(List<?> values, QueryShardContext context) { if (indexOptions() != IndexOptions.NONE) { failIfNotIndexed(); BytesRef[] bytesRefs = new BytesRef[values.size()]; final boolean is5xIndex = context.indexVersionCreated().before(Version.V_6_0_0_beta1); for (int i = 0; i < bytesRefs.length; i++) { BytesRef id; if (is5xIndex) { // 5.x index with index.mapping.single_type = true id = BytesRefs.toBytesRef(values.get(i)); } else { Object idObject = values.get(i); if (idObject instanceof BytesRef) { idObject = ((BytesRef) idObject).utf8ToString(); } id = Uid.encodeId(idObject.toString()); } bytesRefs[i] = id; } return new TermInSetQuery(name(), bytesRefs); } // 5.x index, _uid is indexed return new TermInSetQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values)); }
protected static Nested resolveNested(QueryShardContext context, NestedSortBuilder nestedSort) throws IOException { final Query childQuery = resolveNestedQuery(context, nestedSort, null); if (childQuery == null) { return null; } final ObjectMapper objectMapper = context.nestedScope().getObjectMapper(); final Query parentQuery; if (objectMapper == null) { parentQuery = Queries.newNonNestedFilter(context.indexVersionCreated()); } else { parentQuery = objectMapper.nestedTypeFilter(); } return new Nested(context.bitsetFilter(parentQuery), childQuery, nestedSort); }
public static Query newFilter(QueryShardContext context, String fieldPattern) { final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context .getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { // can only happen when no types exist, so no docs exist either return Queries.newMatchNoDocsQuery("Missing types in \"" + NAME + "\" query."); } final Collection<String> fields; if (context.getObjectMapper(fieldPattern) != null) { // the _field_names field also indexes objects, so we don't have to // do any more work to support exists queries on whole objects fields = Collections.singleton(fieldPattern); } else { fields = context.simpleMatchToIndexNames(fieldPattern); } if (context.indexVersionCreated().before(Version.V_6_1_0)) { return newLegacyExistsQuery(context, fields); } if (fields.size() == 1) { String field = fields.iterator().next(); return newFieldExistsQuery(context, field); } BooleanQuery.Builder boolFilterBuilder = new BooleanQuery.Builder(); for (String field : fields) { boolFilterBuilder.add(newFieldExistsQuery(context, field), BooleanClause.Occur.SHOULD); } return new ConstantScoreQuery(boolFilterBuilder.build()); }
ObjectMapper objectMapper = context.nestedScope().getObjectMapper(); if (objectMapper == null) { parentFilter = context.bitsetFilter(Queries.newNonNestedFilter(context.indexVersionCreated())); } else { parentFilter = context.bitsetFilter(objectMapper.nestedTypeFilter());
if (context.indexVersionCreated().before(Version.V_6_5_0) && nestedSort.getMaxChildren() != Integer.MAX_VALUE) { throw new QueryShardException(context, "max_children is only supported on v6.5.0 or higher");
if (context.indexVersionCreated().before(Version.V_6_5_0) && nestedSort.getMaxChildren() != Integer.MAX_VALUE) { throw new QueryShardException(context, "max_children is only supported on v6.5.0 or higher");
if (context.indexVersionCreated().before(Version.V_6_5_0) && nestedSort.getMaxChildren() != Integer.MAX_VALUE) { throw new QueryShardException(context, "max_children is only supported on v6.5.0 or higher");
@Override public Query termQuery(Object value, QueryShardContext context) { failIfNotIndexed(); TermQuery query = new TermQuery(new Term(name(), indexedValueForSearch(value))); if (boost() == 1f || (context != null && context.indexVersionCreated().before(Version.V_5_0_0_alpha1))) { return query; } return new BoostQuery(query, boost()); }
@Override public Query termQuery(Object value, QueryShardContext context) { failIfNotIndexed(); TermQuery query = new TermQuery(new Term(name(), indexedValueForSearch(value))); if (boost() == 1f || (context != null && context.indexVersionCreated().before(Version.V_5_0_0_alpha1))) { return query; } return new BoostQuery(query, boost()); }
@Override public Query termQuery(Object value, QueryShardContext context) { failIfNotIndexed(); TermQuery query = new TermQuery(new Term(name(), indexedValueForSearch(value))); if (boost() == 1f || (context != null && context.indexVersionCreated().before(Version.V_5_0_0_alpha1))) { return query; } return new BoostQuery(query, boost()); }
String id = uidString.substring(expectedPrefix.length(), uidString.length()); BytesRef encodedId; if (context.indexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { encodedId = Uid.encodeId(id); } else {
if (context.getMapperService().hasNested()) { return Queries.newNonNestedFilter(context.indexVersionCreated()); } else { return new MatchAllDocsQuery();
@Override public Query termsQuery(List<?> values, QueryShardContext context) { if (indexOptions() != IndexOptions.NONE) { failIfNotIndexed(); BytesRef[] bytesRefs = new BytesRef[values.size()]; final boolean is5xIndex = context.indexVersionCreated().before(Version.V_6_0_0_beta1); for (int i = 0; i < bytesRefs.length; i++) { BytesRef id; if (is5xIndex) { // 5.x index with index.mapping.single_type = true id = BytesRefs.toBytesRef(values.get(i)); } else { Object idObject = values.get(i); if (idObject instanceof BytesRef) { idObject = ((BytesRef) idObject).utf8ToString(); } id = Uid.encodeId(idObject.toString()); } bytesRefs[i] = id; } return new TermInSetQuery(name(), bytesRefs); } // 5.x index, _uid is indexed return new TermInSetQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values)); }
@Override public Query termsQuery(List<?> values, QueryShardContext context) { if (indexOptions() != IndexOptions.NONE) { failIfNotIndexed(); BytesRef[] bytesRefs = new BytesRef[values.size()]; final boolean is5xIndex = context.indexVersionCreated().before(Version.V_6_0_0_beta1); for (int i = 0; i < bytesRefs.length; i++) { BytesRef id; if (is5xIndex) { // 5.x index with index.mapping.single_type = true id = BytesRefs.toBytesRef(values.get(i)); } else { Object idObject = values.get(i); if (idObject instanceof BytesRef) { idObject = ((BytesRef) idObject).utf8ToString(); } id = Uid.encodeId(idObject.toString()); } bytesRefs[i] = id; } return new TermInSetQuery(name(), bytesRefs); } // 5.x index, _uid is indexed return new TermInSetQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values)); }
public static Query newFilter(QueryShardContext context, String fieldPattern) { final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context .getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { // can only happen when no types exist, so no docs exist either return Queries.newMatchNoDocsQuery("Missing types in \"" + NAME + "\" query."); } final Collection<String> fields; if (context.getObjectMapper(fieldPattern) != null) { // the _field_names field also indexes objects, so we don't have to // do any more work to support exists queries on whole objects fields = Collections.singleton(fieldPattern); } else { fields = context.simpleMatchToIndexNames(fieldPattern); } if (context.indexVersionCreated().before(Version.V_6_1_0)) { return newLegacyExistsQuery(context, fields); } if (fields.size() == 1) { String field = fields.iterator().next(); return newFieldExistsQuery(context, field); } BooleanQuery.Builder boolFilterBuilder = new BooleanQuery.Builder(); for (String field : fields) { boolFilterBuilder.add(newFieldExistsQuery(context, field), BooleanClause.Occur.SHOULD); } return new ConstantScoreQuery(boolFilterBuilder.build()); }
protected static Nested resolveNested(QueryShardContext context, NestedSortBuilder nestedSort) throws IOException { final Query childQuery = resolveNestedQuery(context, nestedSort, null); if (childQuery == null) { return null; } final ObjectMapper objectMapper = context.nestedScope().getObjectMapper(); final Query parentQuery; if (objectMapper == null) { parentQuery = Queries.newNonNestedFilter(context.indexVersionCreated()); } else { parentQuery = objectMapper.nestedTypeFilter(); } return new Nested(context.bitsetFilter(parentQuery), childQuery, nestedSort); }
protected static Nested resolveNested(QueryShardContext context, NestedSortBuilder nestedSort) throws IOException { final Query childQuery = resolveNestedQuery(context, nestedSort, null); if (childQuery == null) { return null; } final ObjectMapper objectMapper = context.nestedScope().getObjectMapper(); final Query parentQuery; if (objectMapper == null) { parentQuery = Queries.newNonNestedFilter(context.indexVersionCreated()); } else { parentQuery = objectMapper.nestedTypeFilter(); } return new Nested(context.bitsetFilter(parentQuery), childQuery); }