Reference Entry
OpenSearch-Style Search Requests
Other Features · advanced · order 15
Parse and run OpenSearch-style JSON search requests with queries, highlights, aggregations, geo, vector, and script clauses.
OpenSearch-Style Search Requests
Querylight TS now includes a JSON request layer for teams that prefer request objects over class-based query construction.
The JSON DSL is modeled after the OpenSearch and Elasticsearch request format as closely as the current feature set allows.
Basic search request
Raw request JSON:
{
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "vector search",
"operator": "and"
}
}
}
],
"filter": [
{
"term": {
"tags": "tutorial"
}
}
]
}
},
"from": 0,
"size": 10,
"highlight": {
"fields": {
"title": {},
"body": {
"fragment_size": 120
}
}
},
"aggs": {
"tags": {
"terms": {
"field": "tags",
"size": 10
}
},
"prices": {
"stats": {
"field": "price"
}
}
}
}
Send that request from TypeScript like this:
import { searchJsonDsl } from "@tryformation/querylight-ts";
const request = {
query: {
bool: {
must: [
{ match: { title: { query: "vector search", operator: "and" } } }
],
filter: [
{ term: { tags: "tutorial" } }
]
}
},
from: 0,
size: 10,
highlight: {
fields: {
title: {},
body: { fragment_size: 120 }
}
},
aggs: {
tags: { terms: { field: "tags", size: 10 } },
prices: { stats: { field: "price" } }
}
};
const response = await searchJsonDsl({ index, request });
The response shape follows the familiar OpenSearch layout:
tookhits.totalhits.max_scorehits.hitsaggregations
Supported query clauses
match_alltermtermsmatchmulti_matchmatch_phraseprefixwildcardregexpexistsrangebooldis_maxboostinggeo_shapegeo_pointgeo_polygondistance_featurerank_featurescriptscript_scorerrfknnneural_sparseandsparse_vectorvector_rescoresparse_vector_rescore
Supported aggregations
termssignificant_termsvalue_countminmaxsumavgstatsrangehistogramdate_histogram
Notes
searchJsonDsl(...)is the main entrypoint for full request execution.parseJsonDslQuery({ query: ... })parses one query clause into the equivalent Querylight query object.- Script clauses use JavaScript expressions in
script.source. - Reciprocal rank fusion is available via the
rrfclause. - Dense vector retrieval uses
knn. - Sparse retrieval accepts both
neural_sparseandsparse_vector. - Beginner-search bundles created by
createSimpleTextSearchIndex(...)can be executed with a top-levelsimple_text_searchrequest. - Per-hit
_sourcecomes fromStoredSourceIndexwhen yourDocumentIndexmapping includes_source: new StoredSourceIndex(). - Without
StoredSourceIndex, the fallback_sourcefor plainDocumentIndexsearches is the indexed field map. SimpleTextSearchIndexresponses still return the original source object because that helper keeps the input documents around.
If you prefer the existing TypeScript-first API, the class-based query types remain fully supported.