AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
setup:
- skip:
reason: "https://github.com/elastic/elasticsearch/issues/109476"
known_issues:
- cluster_feature: "gte_v8.13.0"
fixed_by: "gte_v8.14.0"
- do:
indices.create:
index: test
body:
mappings:
properties:
numeric_group: { type: integer }
tag: { type: keyword }
- do:
index:
index: test
id: "1"
version_type: external
version: 11
body: { numeric_group: 1, tag: A, sort: 10 }
- do:
index:
index: test
id: "2"
version_type: external
version: 22
body: { numeric_group: 1, tag: B, sort: 6 }
- do:
index:
index: test
id: "3"
version_type: external
version: 33
body: { numeric_group: 1, tag: A, sort: 24 }
- do:
index:
index: test
id: "4"
version_type: external
version: 44
body: { numeric_group: 25, tag: B, sort: 10 }
- do:
index:
index: test
id: "5"
version_type: external
version: 55
body: { numeric_group: 25, tag: A, sort: 5 }
- do:
index:
index: test
id: "6"
version_type: external
version: 66
body: { numeric_group: 3, tag: B, sort: 36 }
- do:
indices.refresh:
index: test
---
"field collapsing":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse: { field: numeric_group }
sort: [{ sort: desc }]
- match: {hits.total: 6 }
- length: {hits.hits: 3 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0.fields.numeric_group: [3] }
- match: {hits.hits.0.sort: [36] }
- match: {hits.hits.0._id: "6" }
- is_false: hits.hits.0.inner_hits
- match: {hits.hits.1._index: test }
- match: {hits.hits.1.fields.numeric_group: [1] }
- match: {hits.hits.1.sort: [24] }
- match: {hits.hits.1._id: "3" }
- is_false: hits.hits.1.inner_hits
- match: {hits.hits.2._index: test }
- match: {hits.hits.2.fields.numeric_group: [25] }
- match: {hits.hits.2.sort: [10] }
- match: {hits.hits.2._id: "4" }
- is_false: hits.hits.2.inner_hits
---
"field collapsing and from":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
from: 2
collapse: { field: numeric_group }
sort: [{ sort: desc }]
- match: {hits.total: 6 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0.fields.numeric_group: [25]}
- match: {hits.hits.0.sort: [10] }
- match: {hits.hits.0._id: "4" }
- is_false: hits.hits.0.inner_hits
---
"field collapsing and inner_hits":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse: { field: numeric_group, inner_hits: { name: sub_hits, size: 2, sort: [{ sort: asc }] } }
sort: [{ sort: desc }]
- match: { hits.total: 6 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.sort: [36] }
- match: { hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1 }
- length: { hits.hits.0.inner_hits.sub_hits.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._id: "6" }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.sort: [24] }
- match: { hits.hits.1._id: "3" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 3 }
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "2" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "1" }
- match: { hits.hits.2._index: test }
- match: { hits.hits.2.fields.numeric_group: [25] }
- match: { hits.hits.2.sort: [10] }
- match: { hits.hits.2._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 2 }
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "5" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
---
"field collapsing, inner_hits, and fields":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse:
field: numeric_group
inner_hits:
name: sub_hits
size: 2
sort: [{ sort: asc }]
fields: ["tag"]
sort: [{ sort: desc }]
- length: { hits.hits: 3 }
- length: { hits.hits.0.inner_hits.sub_hits.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0.fields.tag: ["B"]}
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "2" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0.fields.tag: ["B"]}
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "1" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1.fields.tag: ["A"]}
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "5" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0.fields.tag: ["A"]}
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1.fields.tag: ["B"]}
---
"field collapsing, inner_hits and maxConcurrentGroupRequests":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse: { field: numeric_group, max_concurrent_group_searches: 10, inner_hits: { name: sub_hits, size: 2, sort: [{ sort: asc }] } }
sort: [{ sort: desc }]
- match: { hits.total: 6 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.sort: [36] }
- match: { hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1 }
- length: { hits.hits.0.inner_hits.sub_hits.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._id: "6" }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.sort: [24] }
- match: { hits.hits.1._id: "3" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 3 }
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "2" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "1" }
- match: { hits.hits.2._index: test }
- match: { hits.hits.2.fields.numeric_group: [25] }
- match: { hits.hits.2.sort: [10] }
- match: { hits.hits.2._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 2 }
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "5" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
---
"field collapsing and scroll":
- do:
catch: /cannot use \`collapse\` in a scroll context/
search:
rest_total_hits_as_int: true
index: test
scroll: 1s
body:
collapse: { field: numeric_group }
---
"field collapsing and search_after with invalid sort":
- do:
catch: /Cannot use \[collapse\] in conjunction with \[search_after\] unless the search is sorted on the same field. Multiple sort fields are not allowed./
search:
index: test
body:
collapse: { field: numeric_group }
search_after: [6]
sort: [{ sort: desc }]
- do:
catch: /Cannot use \[collapse\] in conjunction with \[search_after\] unless the search is sorted on the same field. Multiple sort fields are not allowed./
search:
index: test
body:
collapse: { field: numeric_group }
search_after: [6, 42]
sort: [{ numeric_group: asc, sort: desc }]
---
"field collapsing and search_after":
- do:
search:
index: test
body:
collapse: { field: numeric_group }
sort: [{ numeric_group: desc}]
size: 1
- match: { hits.total.value: 6 }
- length: { hits.hits: 1 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [25] }
- match: { hits.hits.0.sort: [25] }
- do:
search:
index: test
body:
collapse: { field: numeric_group }
sort: [{ numeric_group: desc}]
search_after: [25]
size: 2
- match: { hits.total.value: 6 }
- length: { hits.hits: 2 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.sort: [3] }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.sort: [1] }
---
"no hits and inner_hits":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
size: 0
collapse: { field: numeric_group, inner_hits: { name: sub_hits, size: 1} }
sort: [{ sort: desc }]
- match: { hits.total: 6 }
- length: { hits.hits: 0 }
---
"no hits and inner_hits max_score null":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
size: 0
collapse: { field: numeric_group, inner_hits: { name: sub_hits, size: 1} }
sort: [{ sort: desc }]
- match: { hits.max_score: null }
---
"field collapsing and multiple inner_hits":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse:
field: numeric_group
inner_hits:
- { name: sub_hits_asc, size: 2, sort: [{ sort: asc }] }
- { name: sub_hits_desc, size: 1, sort: [{ sort: desc }] }
sort: [{ sort: desc }]
- match: { hits.total: 6 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.sort: [36] }
- match: { hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits_asc.hits.total: 1 }
- length: { hits.hits.0.inner_hits.sub_hits_asc.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits_asc.hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits_desc.hits.total: 1 }
- length: { hits.hits.0.inner_hits.sub_hits_desc.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits_desc.hits.hits.0._id: "6" }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.sort: [24] }
- match: { hits.hits.1._id: "3" }
- match: { hits.hits.1.inner_hits.sub_hits_asc.hits.total: 3 }
- length: { hits.hits.1.inner_hits.sub_hits_asc.hits.hits: 2 }
- match: { hits.hits.1.inner_hits.sub_hits_asc.hits.hits.0._id: "2" }
- match: { hits.hits.1.inner_hits.sub_hits_asc.hits.hits.1._id: "1" }
- match: { hits.hits.1.inner_hits.sub_hits_desc.hits.total: 3 }
- length: { hits.hits.1.inner_hits.sub_hits_desc.hits.hits: 1 }
- match: { hits.hits.1.inner_hits.sub_hits_desc.hits.hits.0._id: "3" }
- match: { hits.hits.2._index: test }
- match: { hits.hits.2.fields.numeric_group: [25] }
- match: { hits.hits.2.sort: [10] }
- match: { hits.hits.2._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits_asc.hits.total: 2 }
- length: { hits.hits.2.inner_hits.sub_hits_asc.hits.hits: 2 }
- match: { hits.hits.2.inner_hits.sub_hits_asc.hits.hits.0._id: "5" }
- match: { hits.hits.2.inner_hits.sub_hits_asc.hits.hits.1._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits_desc.hits.total: 2 }
- length: { hits.hits.2.inner_hits.sub_hits_desc.hits.hits: 1 }
- match: { hits.hits.2.inner_hits.sub_hits_desc.hits.hits.0._id: "4" }
---
"field collapsing, inner_hits and version":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse: { field: numeric_group, inner_hits: { name: sub_hits, version: true, size: 2, sort: [{ sort: asc }] } }
sort: [{ sort: desc }]
version: true
- match: { hits.total: 6 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.sort: [36] }
- match: { hits.hits.0._id: "6" }
- match: { hits.hits.0._version: 66 }
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1 }
- length: { hits.hits.0.inner_hits.sub_hits.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._version: 66 }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.sort: [24] }
- match: { hits.hits.1._id: "3" }
- match: { hits.hits.1._version: 33 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 3 }
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "2" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._version: 22 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "1" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._version: 11 }
- match: { hits.hits.2._index: test }
- match: { hits.hits.2.fields.numeric_group: [25] }
- match: { hits.hits.2.sort: [10] }
- match: { hits.hits.2._id: "4" }
- match: { hits.hits.2._version: 44 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 2 }
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "5" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._version: 55 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._version: 44 }
---
"field collapsing on a field alias":
- do:
indices.create:
index: alias-test
body:
mappings:
properties:
numeric_group: { type: alias, path: other_numeric_group }
other_numeric_group: { type: integer }
- do:
index:
index: alias-test
id: "1"
body: { other_numeric_group: 1, sort: 6 }
- do:
index:
index: alias-test
id: "2"
body: { other_numeric_group: 25, sort: 10 }
- do:
indices.refresh:
index: alias-test
- do:
search:
rest_total_hits_as_int: true
index: [alias-test, test]
body:
collapse: { field: numeric_group, inner_hits: { name: sub_hits } }
sort: [{ sort: desc }]
- match: { hits.total: 8 }
- length: { hits.hits: 3 }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1}
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 4}
- match: { hits.hits.2.fields.numeric_group: [25] }
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 3}
---
"field collapsing, inner_hits and seq_no":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
collapse: { field: numeric_group, inner_hits: {
name: sub_hits, seq_no_primary_term: true, size: 2, sort: [{ sort: asc }]
} }
sort: [{ sort: desc }]
- match: { hits.total: 6 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0.fields.numeric_group: [3] }
- match: { hits.hits.0.sort: [36] }
- match: { hits.hits.0._id: "6" }
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1 }
- length: { hits.hits.0.inner_hits.sub_hits.hits.hits: 1 }
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._id: "6" }
- gte: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._seq_no: 0 }
- gte: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._primary_term: 1 }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1.fields.numeric_group: [1] }
- match: { hits.hits.1.sort: [24] }
- match: { hits.hits.1._id: "3" }
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 3 }
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "2" }
- gte: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._seq_no: 0 }
- gte: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._primary_term: 1 }
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "1" }
- gte: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._seq_no: 0 }
- gte: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._primary_term: 1 }
- match: { hits.hits.2._index: test }
- match: { hits.hits.2.fields.numeric_group: [25] }
- match: { hits.hits.2.sort: [10] }
- match: { hits.hits.2._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 2 }
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "5" }
- gte: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._seq_no: 0 }
- gte: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._primary_term: 1 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
- gte: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._seq_no: 0 }
- gte: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._primary_term: 1 }
---
"Test collapse with inner_hits and missing name fails":
- requires:
cluster_features: ["gte_v8.13.0"]
reason: fixed in 8.13
- do:
catch: bad_request
search:
index: test
body:
collapse: { field: numeric_group, inner_hits: { size: 1 } }
sort: [{ sort: desc }]