private static void setDefaultIndexTypeFields(QueryShardContext context, Item item, List<String> moreLikeFields, boolean useDefaultField) { if (item.index() == null) { item.index(context.index().getName()); } if (item.type() == null) { if (context.queryTypes().size() > 1) { throw new QueryShardException(context, "ambiguous type for item with id: " + item.id() + " and index: " + item.index()); } else { item.type(context.queryTypes().iterator().next()); } } // default fields if not present but don't override for artificial docs if ((item.fields() == null || item.fields().length == 0) && item.doc() == null) { if (useDefaultField) { item.fields("*"); } else { item.fields(moreLikeFields.toArray(new String[moreLikeFields.size()])); } } }
docs.add(docMapper.parse(source(context.index().getName(), type, "_temp_id", document, documentXContentType))); docMapper = docMapperForType.getDocumentMapper(); for (BytesReference document : documents) { docs.add(docMapper.parse(source(context.index().getName(), documentType, "_temp_id", document, documentXContentType)));
/** * This termQuery impl looks at the context to determine the index that * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY * if the value matches this index. This can be useful if aliases or * wildcards are used but the aim is to restrict the query to specific * indices */ @Override public Query termQuery(Object value, @Nullable QueryShardContext context) { if (isSameIndex(value, context.getFullyQualifiedIndex().getName())) { return Queries.newMatchAllQuery(); } else { return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + value); } }
docs.add(docMapper.parse(source(context.index().getName(), type, "_temp_id", document, documentXContentType))); docMapper = docMapperForType.getDocumentMapper(); for (BytesReference document : documents) { docs.add(docMapper.parse(source(context.index().getName(), documentType, "_temp_id", document, documentXContentType)));
@Override protected ScoreFunction doToFunction(QueryShardContext context) { final int salt = (context.index().getName().hashCode() << 10) | context.getShardId(); if (seed == null) { throw new IllegalArgumentException("Field [" + field + "] is not mapped on [" + context.index() + "] and cannot be used as a source of random numbers.");
public QueryShardException(QueryShardContext context, String msg, Throwable cause, Object... args) { super(msg, cause, args); setIndex(context.index()); }
/** * This termQuery impl looks at the context to determine the index that * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY * if the value matches this index. This can be useful if aliases or * wildcards are used but the aim is to restrict the query to specific * indices */ @Override public Query termQuery(Object value, @Nullable QueryShardContext context) { if (isSameIndex(value, context.index().getName())) { return Queries.newMatchAllQuery(); } else { return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + value); } }
@Override public Query termsQuery(List values, QueryShardContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.index().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + values); }
private static void setDefaultIndexTypeFields(QueryShardContext context, Item item, List<String> moreLikeFields, boolean useDefaultField) { if (item.index() == null) { item.index(context.index().getName()); } if (item.type() == null) { if (context.queryTypes().size() > 1) { throw new QueryShardException(context, "ambiguous type for item with id: " + item.id() + " and index: " + item.index()); } else { item.type(context.queryTypes().iterator().next()); } } // default fields if not present but don't override for artificial docs if ((item.fields() == null || item.fields().length == 0) && item.doc() == null) { if (useDefaultField) { item.fields("*"); } else { item.fields(moreLikeFields.toArray(new String[moreLikeFields.size()])); } } }
private static void setDefaultIndexTypeFields(QueryShardContext context, Item item, List<String> moreLikeFields, boolean useDefaultField) { if (item.index() == null) { item.index(context.index().getName()); } if (item.type() == null) { if (context.queryTypes().size() > 1) { throw new QueryShardException(context, "ambiguous type for item with id: " + item.id() + " and index: " + item.index()); } else { item.type(context.queryTypes().iterator().next()); } } // default fields if not present but don't override for artificial docs if ((item.fields() == null || item.fields().length == 0) && item.doc() == null) { if (useDefaultField) { item.fields("*"); } else { item.fields(moreLikeFields.toArray(new String[moreLikeFields.size()])); } } }
/** * This termQuery impl looks at the context to determine the index that * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY * if the value matches this index. This can be useful if aliases or * wildcards are used but the aim is to restrict the query to specific * indices */ @Override public Query termQuery(Object value, @Nullable QueryShardContext context) { if (isSameIndex(value, context.getFullyQualifiedIndex().getName())) { return Queries.newMatchAllQuery(); } else { return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + value); } }
/** * This termQuery impl looks at the context to determine the index that * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY * if the value matches this index. This can be useful if aliases or * wildcards are used but the aim is to restrict the query to specific * indices */ @Override public Query termQuery(Object value, @Nullable QueryShardContext context) { if (isSameIndex(value, context.getFullyQualifiedIndex().getName())) { return Queries.newMatchAllQuery(); } else { return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + value); } }
@Override protected ScoreFunction doToFunction(QueryShardContext context) { final MappedFieldType fieldType; if (context.getIndexSettings().isSingleType()) { fieldType = context.getMapperService().fullName(IdFieldMapper.NAME); } else { fieldType = context.getMapperService().fullName(UidFieldMapper.NAME); } if (fieldType == null) { // mapper could be null if we are on a shard with no docs yet, so this won't actually be used return new RandomScoreFunction(); } final int salt = (context.index().getName().hashCode() << 10) | context.getShardId(); final IndexFieldData<?> uidFieldData = context.getForField(fieldType); return new RandomScoreFunction(this.seed == null ? hash(context.nowInMillis()) : seed, salt, uidFieldData); }
@Override protected ScoreFunction doToFunction(QueryShardContext context) { final int salt = (context.index().getName().hashCode() << 10) | context.getShardId(); if (seed == null) { throw new IllegalArgumentException("Field [" + field + "] is not mapped on [" + context.index() + "] and cannot be used as a source of random numbers.");
@Override protected ScoreFunction doToFunction(QueryShardContext context) { final int salt = (context.index().getName().hashCode() << 10) | context.getShardId(); if (seed == null) { throw new IllegalArgumentException("Field [" + field + "] is not mapped on [" + context.index() + "] and cannot be used as a source of random numbers.");