Tabnine Logo
InnerHitBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
InnerHitBuilder
in
org.elasticsearch.index.query

Best Java code snippets using org.elasticsearch.index.query.InnerHitBuilder (Showing top 20 results out of 315)

origin: NLPchina/elasticsearch-sql

if (condition.getInnerHits() != null) {
  try (JsonXContentParser parser = new JsonXContentParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, new JsonFactory().createParser(condition.getInnerHits()))) {
    ihb = InnerHitBuilder.fromXContent(parser);
  } catch (IOException e) {
    throw new IllegalArgumentException("couldn't parse inner_hits: " + e.getMessage(), e);
origin: org.elasticsearch/elasticsearch

  @Override
  protected void doBuild(SearchContext parentSearchContext,
           InnerHitsContext innerHitsContext) throws IOException {
    QueryShardContext queryShardContext = parentSearchContext.getQueryShardContext();
    ObjectMapper nestedObjectMapper = queryShardContext.getObjectMapper(path);
    if (nestedObjectMapper == null) {
      if (innerHitBuilder.isIgnoreUnmapped() == false) {
        throw new IllegalStateException("[" + query.getName() + "] no mapping found for type [" + path + "]");
      } else {
        return;
      }
    }
    String name =  innerHitBuilder.getName() != null ? innerHitBuilder.getName() : nestedObjectMapper.fullPath();
    ObjectMapper parentObjectMapper = queryShardContext.nestedScope().nextLevel(nestedObjectMapper);
    NestedInnerHitSubContext nestedInnerHits = new NestedInnerHitSubContext(
      name, parentSearchContext, parentObjectMapper, nestedObjectMapper
    );
    setupInnerHitsContext(queryShardContext, nestedInnerHits);
    queryShardContext.nestedScope().previousLevel();
    innerHitsContext.addInnerHitDefinition(nestedInnerHits);
  }
}
origin: org.elasticsearch/elasticsearch

public static InnerHitBuilder fromXContent(XContentParser parser) throws IOException {
  return PARSER.parse(parser, new InnerHitBuilder(), null);
}
origin: org.elasticsearch/elasticsearch

public final void build(SearchContext parentSearchContext, InnerHitsContext innerHitsContext) throws IOException {
  long innerResultWindow = innerHitBuilder.getFrom() + innerHitBuilder.getSize();
  int maxInnerResultWindow = parentSearchContext.mapperService().getIndexSettings().getMaxInnerResultWindow();
  if (innerResultWindow > maxInnerResultWindow) {
    throw new IllegalArgumentException(
      "Inner result window is too large, the inner hit definition's [" + innerHitBuilder.getName() +
        "]'s from + size must be less than or equal to: [" + maxInnerResultWindow + "] but was [" + innerResultWindow +
        "]. This limit can be set by changing the [" + IndexSettings.MAX_INNER_RESULT_WINDOW_SETTING.getKey() +
        "] index level setting."
    );
  }
  doBuild(parentSearchContext, innerHitsContext);
}
origin: org.elasticsearch/elasticsearch

private SearchSourceBuilder buildExpandSearchSourceBuilder(InnerHitBuilder options, CollapseBuilder innerCollapseBuilder) {
  SearchSourceBuilder groupSource = new SearchSourceBuilder();
  groupSource.from(options.getFrom());
  groupSource.size(options.getSize());
  if (options.getSorts() != null) {
    options.getSorts().forEach(groupSource::sort);
  if (options.getFetchSourceContext() != null) {
    if (options.getFetchSourceContext().includes() == null && options.getFetchSourceContext().excludes() == null) {
      groupSource.fetchSource(options.getFetchSourceContext().fetchSource());
    } else {
      groupSource.fetchSource(options.getFetchSourceContext().includes(),
        options.getFetchSourceContext().excludes());
  if (options.getDocValueFields() != null) {
    options.getDocValueFields().forEach(ff -> groupSource.docValueField(ff.field, ff.format));
  if (options.getStoredFieldsContext() != null && options.getStoredFieldsContext().fieldNames() != null) {
    options.getStoredFieldsContext().fieldNames().forEach(groupSource::storedField);
  if (options.getScriptFields() != null) {
    for (SearchSourceBuilder.ScriptField field : options.getScriptFields()) {
      groupSource.scriptField(field.fieldName(), field.script());
  if (options.getHighlightBuilder() != null) {
    groupSource.highlighter(options.getHighlightBuilder());
  groupSource.explain(options.isExplain());
  groupSource.trackScores(options.isTrackScores());
  groupSource.version(options.isVersion());
origin: org.elasticsearch/elasticsearch

@Override
public void extractInnerHitBuilders(Map<String, InnerHitContextBuilder> innerHits) {
  if (innerHitBuilder != null) {
    Map<String, InnerHitContextBuilder> children = new HashMap<>();
    InnerHitContextBuilder.extractInnerHits(query, children);
    InnerHitContextBuilder innerHitContextBuilder = new NestedInnerHitContextBuilder(path, query, innerHitBuilder, children);
    String name = innerHitBuilder.getName() != null ? innerHitBuilder.getName() : path;
    innerHits.put(name, innerHitContextBuilder);
  }
}
origin: org.elasticsearch/elasticsearch

/**
 * Sets whether the query builder should ignore unmapped paths (and run a
 * {@link MatchNoDocsQuery} in place of this query) or throw an exception if
 * the path is unmapped.
 */
public NestedQueryBuilder ignoreUnmapped(boolean ignoreUnmapped) {
  this.ignoreUnmapped = ignoreUnmapped;
  if (innerHitBuilder != null) {
    innerHitBuilder.setIgnoreUnmapped(ignoreUnmapped);
  }
  return this;
}
origin: org.elasticsearch/elasticsearch

CollapseBuilder innerCollapseBuilder = innerHitBuilder.getInnerCollapseBuilder();
SearchSourceBuilder sourceBuilder = buildExpandSearchSourceBuilder(innerHitBuilder, innerCollapseBuilder)
  .query(groupQuery)
      hit.setInnerHits(new HashMap<>(innerHitBuilders.size()));
    hit.getInnerHits().put(innerHitBuilder.getName(), innerHits);
origin: DigitalPebble/storm-crawler

InnerHitBuilder ihb = new InnerHitBuilder();
ihb.setSize(maxURLsPerBucket);
ihb.setName("urls_per_bucket");
      bucketSortField).order(SortOrder.ASC);
  sorts.add(bucketsorter);
  ihb.setSorts(sorts);
origin: apache/servicemix-bundles

  @Override
  protected void doBuild(SearchContext parentSearchContext,
           InnerHitsContext innerHitsContext) throws IOException {
    QueryShardContext queryShardContext = parentSearchContext.getQueryShardContext();
    ObjectMapper nestedObjectMapper = queryShardContext.getObjectMapper(path);
    if (nestedObjectMapper == null) {
      if (innerHitBuilder.isIgnoreUnmapped() == false) {
        throw new IllegalStateException("[" + query.getName() + "] no mapping found for type [" + path + "]");
      } else {
        return;
      }
    }
    String name =  innerHitBuilder.getName() != null ? innerHitBuilder.getName() : nestedObjectMapper.fullPath();
    ObjectMapper parentObjectMapper = queryShardContext.nestedScope().nextLevel(nestedObjectMapper);
    NestedInnerHitSubContext nestedInnerHits = new NestedInnerHitSubContext(
      name, parentSearchContext, parentObjectMapper, nestedObjectMapper
    );
    setupInnerHitsContext(queryShardContext, nestedInnerHits);
    queryShardContext.nestedScope().previousLevel();
    innerHitsContext.addInnerHitDefinition(nestedInnerHits);
  }
}
origin: org.elasticsearch/elasticsearch

protected void setupInnerHitsContext(QueryShardContext queryShardContext,
                   InnerHitsContext.InnerHitSubContext innerHitsContext) throws IOException {
  innerHitsContext.from(innerHitBuilder.getFrom());
  innerHitsContext.size(innerHitBuilder.getSize());
  innerHitsContext.explain(innerHitBuilder.isExplain());
  innerHitsContext.version(innerHitBuilder.isVersion());
  innerHitsContext.trackScores(innerHitBuilder.isTrackScores());
  if (innerHitBuilder.getStoredFieldsContext() != null) {
    innerHitsContext.storedFieldsContext(innerHitBuilder.getStoredFieldsContext());
  if (innerHitBuilder.getDocValueFields() != null) {
    innerHitsContext.docValueFieldsContext(new DocValueFieldsContext(innerHitBuilder.getDocValueFields()));
  if (innerHitBuilder.getScriptFields() != null) {
    for (SearchSourceBuilder.ScriptField field : innerHitBuilder.getScriptFields()) {
      QueryShardContext innerContext = innerHitsContext.getQueryShardContext();
      SearchScript.Factory factory = innerContext.getScriptService().compile(field.script(), SearchScript.CONTEXT);
  if (innerHitBuilder.getFetchSourceContext() != null) {
    innerHitsContext.fetchSourceContext(innerHitBuilder.getFetchSourceContext() );
  if (innerHitBuilder.getSorts() != null) {
    Optional<SortAndFormats> optionalSort = SortBuilder.buildSort(innerHitBuilder.getSorts(), queryShardContext);
    if (optionalSort.isPresent()) {
      innerHitsContext.sort(optionalSort.get());
  if (innerHitBuilder.getHighlightBuilder() != null) {
    innerHitsContext.highlight(innerHitBuilder.getHighlightBuilder().build(queryShardContext));
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public final void build(SearchContext parentSearchContext, InnerHitsContext innerHitsContext) throws IOException {
  long innerResultWindow = innerHitBuilder.getFrom() + innerHitBuilder.getSize();
  int maxInnerResultWindow = parentSearchContext.mapperService().getIndexSettings().getMaxInnerResultWindow();
  if (innerResultWindow > maxInnerResultWindow) {
    throw new IllegalArgumentException(
      "Inner result window is too large, the inner hit definition's [" + innerHitBuilder.getName() +
        "]'s from + size must be less than or equal to: [" + maxInnerResultWindow + "] but was [" + innerResultWindow +
        "]. This limit can be set by changing the [" + IndexSettings.MAX_INNER_RESULT_WINDOW_SETTING.getKey() +
        "] index level setting."
    );
  }
  doBuild(parentSearchContext, innerHitsContext);
}
origin: com.strapdata.elasticsearch.plugin/parent-join

  @Override
  protected void extractInnerHitBuilders(Map<String, InnerHitContextBuilder> innerHits) {
    if (innerHitBuilder != null) {
      Map<String, InnerHitContextBuilder> children = new HashMap<>();
      InnerHitContextBuilder.extractInnerHits(query, children);
      String name = innerHitBuilder.getName() != null ? innerHitBuilder.getName() : type;
      InnerHitContextBuilder innerHitContextBuilder =
        new ParentChildInnerHitContextBuilder(type, true, query, innerHitBuilder, children);
      innerHits.put(name, innerHitContextBuilder);
    }
  }
}
origin: org.elasticsearch/elasticsearch

public NestedQueryBuilder innerHit(InnerHitBuilder innerHitBuilder) {
  this.innerHitBuilder = innerHitBuilder;
  innerHitBuilder.setIgnoreUnmapped(ignoreUnmapped);
  return this;
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

CollapseBuilder innerCollapseBuilder = innerHitBuilder.getInnerCollapseBuilder();
SearchSourceBuilder sourceBuilder = buildExpandSearchSourceBuilder(innerHitBuilder, innerCollapseBuilder)
  .query(groupQuery)
      hit.setInnerHits(new HashMap<>(innerHitBuilders.size()));
    hit.getInnerHits().put(innerHitBuilder.getName(), innerHits);
origin: com.strapdata.elasticsearch/elasticsearch

private SearchSourceBuilder buildExpandSearchSourceBuilder(InnerHitBuilder options) {
  SearchSourceBuilder groupSource = new SearchSourceBuilder();
  groupSource.from(options.getFrom());
  groupSource.size(options.getSize());
  if (options.getSorts() != null) {
    options.getSorts().forEach(groupSource::sort);
  if (options.getFetchSourceContext() != null) {
    if (options.getFetchSourceContext().includes() == null && options.getFetchSourceContext().excludes() == null) {
      groupSource.fetchSource(options.getFetchSourceContext().fetchSource());
    } else {
      groupSource.fetchSource(options.getFetchSourceContext().includes(),
        options.getFetchSourceContext().excludes());
  if (options.getDocValueFields() != null) {
    options.getDocValueFields().forEach(groupSource::docValueField);
  if (options.getStoredFieldsContext() != null && options.getStoredFieldsContext().fieldNames() != null) {
    options.getStoredFieldsContext().fieldNames().forEach(groupSource::storedField);
  if (options.getScriptFields() != null) {
    for (SearchSourceBuilder.ScriptField field : options.getScriptFields()) {
      groupSource.scriptField(field.fieldName(), field.script());
  if (options.getHighlightBuilder() != null) {
    groupSource.highlighter(options.getHighlightBuilder());
  groupSource.explain(options.isExplain());
  groupSource.trackScores(options.isTrackScores());
  return groupSource;
origin: org.elasticsearch.plugin/parent-join-client

private void handleJoinFieldInnerHits(SearchContext context, InnerHitsContext innerHitsContext) throws IOException {
  QueryShardContext queryShardContext = context.getQueryShardContext();
  ParentJoinFieldMapper joinFieldMapper = ParentJoinFieldMapper.getMapper(context.mapperService());
  if (joinFieldMapper != null) {
    String name = innerHitBuilder.getName() != null ? innerHitBuilder.getName() : typeName;
    JoinFieldInnerHitSubContext joinFieldInnerHits = new JoinFieldInnerHitSubContext(name, context, typeName,
      fetchChildInnerHits, joinFieldMapper);
    setupInnerHitsContext(queryShardContext, joinFieldInnerHits);
    innerHitsContext.addInnerHitDefinition(joinFieldInnerHits);
  } else {
    if (innerHitBuilder.isIgnoreUnmapped() == false) {
      throw new IllegalStateException("no join field has been configured");
    }
  }
}
origin: org.elasticsearch/elasticsearch

  query = parseInnerQueryBuilder(parser);
} else if (INNER_HITS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
  innerHitBuilder = InnerHitBuilder.fromXContent(parser);
} else {
  throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
origin: apache/servicemix-bundles

public final void build(SearchContext parentSearchContext, InnerHitsContext innerHitsContext) throws IOException {
  long innerResultWindow = innerHitBuilder.getFrom() + innerHitBuilder.getSize();
  int maxInnerResultWindow = parentSearchContext.mapperService().getIndexSettings().getMaxInnerResultWindow();
  if (innerResultWindow > maxInnerResultWindow) {
    throw new IllegalArgumentException(
      "Inner result window is too large, the inner hit definition's [" + innerHitBuilder.getName() +
        "]'s from + size must be less than or equal to: [" + maxInnerResultWindow + "] but was [" + innerResultWindow +
        "]. This limit can be set by changing the [" + IndexSettings.MAX_INNER_RESULT_WINDOW_SETTING.getKey() +
        "] index level setting."
    );
  }
  doBuild(parentSearchContext, innerHitsContext);
}
origin: org.elasticsearch.plugin/parent-join-client

@Override
protected void extractInnerHitBuilders(Map<String, InnerHitContextBuilder> innerHits) {
  if (innerHitBuilder != null) {
    Map<String, InnerHitContextBuilder> children = new HashMap<>();
    InnerHitContextBuilder.extractInnerHits(query, children);
    String name = innerHitBuilder.getName() != null ? innerHitBuilder.getName() : type;
    InnerHitContextBuilder innerHitContextBuilder =
      new ParentChildInnerHitContextBuilder(type, false, query, innerHitBuilder, children);
    innerHits.put(name, innerHitContextBuilder);
  }
}
org.elasticsearch.index.queryInnerHitBuilder

Most used methods

  • fromXContent
  • getName
  • isIgnoreUnmapped
    Whether to include inner hits in the search response hits if required mappings is missing
  • <init>
    Read from a stream.
  • setIgnoreUnmapped
  • getDocValueFields
    Gets the docvalue fields.
  • getFetchSourceContext
  • getFrom
  • getHighlightBuilder
  • getScriptFields
  • getSize
  • getSorts
  • getSize,
  • getSorts,
  • getStoredFieldsContext,
  • isExplain,
  • isTrackScores,
  • isVersion,
  • setStoredFieldNames,
  • toXContent,
  • writeToBWC,
  • writeToCollapseBWC

Popular in Java

  • Reading from database using SQL prepared statement
  • scheduleAtFixedRate (Timer)
  • getSupportFragmentManager (FragmentActivity)
  • runOnUiThread (Activity)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Option (scala)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now