Search in sources :

Example 1 with FieldScript

use of org.opensearch.script.FieldScript in project OpenSearch by opensearch-project.

the class ExpressionFieldScriptTests method testFieldAccessWithFieldAlias.

public void testFieldAccessWithFieldAlias() throws IOException {
    FieldScript script = compile("doc['alias'].value").newInstance(null);
    script.setDocument(1);
    Object result = script.execute();
    assertThat(result, equalTo(2.718));
}
Also used : FieldScript(org.opensearch.script.FieldScript)

Example 2 with FieldScript

use of org.opensearch.script.FieldScript in project OpenSearch by opensearch-project.

the class ExpressionFieldScriptTests method testFieldAccess.

public void testFieldAccess() throws IOException {
    FieldScript script = compile("doc['field'].value").newInstance(null);
    script.setDocument(1);
    Object result = script.execute();
    assertThat(result, equalTo(2.718));
}
Also used : FieldScript(org.opensearch.script.FieldScript)

Example 3 with FieldScript

use of org.opensearch.script.FieldScript in project OpenSearch by opensearch-project.

the class InnerHitContextBuilder method setupInnerHitsContext.

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.seqNoAndPrimaryTerm(innerHitBuilder.isSeqNoAndPrimaryTerm());
    innerHitsContext.trackScores(innerHitBuilder.isTrackScores());
    if (innerHitBuilder.getStoredFieldsContext() != null) {
        innerHitsContext.storedFieldsContext(innerHitBuilder.getStoredFieldsContext());
    }
    if (innerHitBuilder.getDocValueFields() != null) {
        FetchDocValuesContext docValuesContext = FetchDocValuesContext.create(queryShardContext.getMapperService(), innerHitBuilder.getDocValueFields());
        innerHitsContext.docValuesContext(docValuesContext);
    }
    if (innerHitBuilder.getFetchFields() != null) {
        String indexName = queryShardContext.index().getName();
        FetchFieldsContext fieldsContext = new FetchFieldsContext(innerHitBuilder.getFetchFields());
        innerHitsContext.fetchFieldsContext(fieldsContext);
    }
    if (innerHitBuilder.getScriptFields() != null) {
        for (SearchSourceBuilder.ScriptField field : innerHitBuilder.getScriptFields()) {
            QueryShardContext innerContext = innerHitsContext.getQueryShardContext();
            FieldScript.Factory factory = innerContext.compile(field.script(), FieldScript.CONTEXT);
            FieldScript.LeafFactory fieldScript = factory.newFactory(field.script().getParams(), innerContext.lookup());
            innerHitsContext.scriptFields().add(new org.opensearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(field.fieldName(), fieldScript, field.ignoreFailure()));
        }
    }
    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));
    }
    ParsedQuery parsedQuery = new ParsedQuery(query.toQuery(queryShardContext), queryShardContext.copyNamedQueries());
    innerHitsContext.parsedQuery(parsedQuery);
    Map<String, InnerHitsContext.InnerHitSubContext> baseChildren = buildChildInnerHits(innerHitsContext.parentSearchContext(), children);
    innerHitsContext.setChildInnerHits(baseChildren);
}
Also used : FetchDocValuesContext(org.opensearch.search.fetch.subphase.FetchDocValuesContext) FieldScript(org.opensearch.script.FieldScript) SortAndFormats(org.opensearch.search.sort.SortAndFormats) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) FetchFieldsContext(org.opensearch.search.fetch.subphase.FetchFieldsContext)

Aggregations

FieldScript (org.opensearch.script.FieldScript)3 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)1 FetchDocValuesContext (org.opensearch.search.fetch.subphase.FetchDocValuesContext)1 FetchFieldsContext (org.opensearch.search.fetch.subphase.FetchFieldsContext)1 SortAndFormats (org.opensearch.search.sort.SortAndFormats)1