Skip to content

[FEATURE] Support of agentic search queries for conversational agents #1892

@ocuenca-coursera

Description

@ocuenca-coursera

Is your feature request related to a problem?

OpenSearch 3.2+ introduced the agentic query type, a specialized query that translates natural language questions into DSL queries via a preconfigured agent and search pipeline. The OpenSearch Java client does not currently support this query type, forcing users to fall back on raw JSON or low-level REST calls to use agentic search from Java applications.

What solution would you like?

Add AgenticQuery as a new variant of the Query tagged union in the Java client, following the same patterns used by existing query types like HybridQuery. The query should support the following fields:

Field Type Required Description
query_text String Yes The natural language question
query_fields List<String> No Index fields the agent should consider
memory_id String No Memory ID for conversational context

Here's how to use it:

  import org.opensearch.client.opensearch.OpenSearchClient;                                                                                                                                                                                                                                                               
  import org.opensearch.client.opensearch.core.SearchRequest;                                                                                                                                                                                                                                                             
  import org.opensearch.client.opensearch.core.SearchResponse;                                                                                                                                                                                                                                                            
  import org.opensearch.client.opensearch._types.query_dsl.AgenticQuery;                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                          
  // Build and execute the search request
  SearchResponse<MyDocument> response = client.search(s -> s
      .index("my-index")
      .searchPipeline("my-agentic-pipeline")
      .query(q -> q
          .agentic(a -> a
              .queryText("What is the best selling product last quarter?")
              .queryFields("title", "description", "category")
              .memoryId("conversation-abc-123")
          )
      ),
      MyDocument.class
  );

This involves:

  • Creating AgenticQuery.java (with builder, serialization/deserialization, and QueryVariant implementation)
  • Registering the Agentic kind in Query.java (enum value, getters, builder methods, deserializer)
  • Adding a convenience factory method in QueryBuilders.java
  • Adding a unit test (AgenticQueryTest.java)

What alternatives have you considered?

  • Using JsonData / raw JSON queries: Users can construct agentic queries as raw JSON via the wrapper query or low-level REST client, but this bypasses the type-safe builder API and loses IDE autocompletion, compile-time validation, and consistency with the rest of the client.
  • Waiting for code generation: The client code is partially generated from the OpenSearch spec. However, the spec may not yet include the agentic query definition, so a manual addition unblocks users sooner.

Do you have any additional context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions