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
"search with search_after parameter":
- do:
indices.create:
index: test
- do:
index:
index: test
id: "1"
body: { id: 1, foo: bar, age: 18 }
- do:
index:
index: test
id: "42"
body: { id: 42, foo: bar, age: 18 }
- do:
index:
index: test
id: "172"
body: { id: 172, foo: bar, age: 24 }
- do:
indices.refresh:
index: test
- do:
search:
rest_total_hits_as_int: true
index: test
body:
size: 1
query:
match:
foo: bar
sort: [{ age: desc }, { id: desc }]
- match: {hits.total: 3 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._id: "172" }
- match: {hits.hits.0.sort: [24, 172] }
- do:
search:
rest_total_hits_as_int: true
index: test
body:
size: 1
query:
match:
foo: bar
sort: [{ age: desc }, { id: desc }]
search_after: [24, 172]
- match: {hits.total: 3 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._id: "42" }
- match: {hits.hits.0.sort: [18, 42] }
- do:
search:
rest_total_hits_as_int: true
index: test
body:
size: 1
query:
match:
foo: bar
sort: [ { age: desc }, { id: desc } ]
search_after: [18, 42]
- match: {hits.total: 3}
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._id: "1" }
- match: {hits.hits.0.sort: [18, 1] }
- do:
search:
rest_total_hits_as_int: true
index: test
body:
size: 1
query:
match:
foo: bar
sort: [{ age: desc }, { id: desc } ]
search_after: [18, 1]
- match: {hits.total: 3}
- length: {hits.hits: 0 }
---
"date":
- do:
indices.create:
index: test
body:
mappings:
properties:
timestamp:
type: date
format: yyyy-MM-dd HH:mm:ss.SSS
- do:
bulk:
refresh: true
index: test
body: |
{"index":{}}
{"timestamp":"2019-10-21 00:30:04.828"}
{"index":{}}
{"timestamp":"2019-10-21 08:30:04.828"}
- do:
search:
index: test
body:
size: 1
sort: [{ timestamp: desc }]
- match: {hits.total.value: 2 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._source.timestamp: "2019-10-21 08:30:04.828" }
- match: {hits.hits.0.sort: [1571646604828] }
# search_after with the sort
- do:
search:
index: test
body:
size: 1
sort: [{ timestamp: desc }]
search_after: [1571646604828]
- match: {hits.total.value: 2 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._source.timestamp: "2019-10-21 00:30:04.828" }
- match: {hits.hits.0.sort: [1571617804828] }
# search_after with the formatted date
- do:
search:
index: test
body:
size: 1
sort: [{ timestamp: desc }]
search_after: ["2019-10-21 08:30:04.828"]
- match: {hits.total.value: 2 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._source.timestamp: "2019-10-21 00:30:04.828" }
- match: {hits.hits.0.sort: [1571617804828] }
---
"date_nanos":
- requires:
cluster_features: ["gte_v7.10.0"]
reason: fixed in 7.10.0
- do:
indices.create:
index: test
body:
mappings:
properties:
timestamp:
type: date_nanos
format: yyyy-MM-dd HH:mm:ss.SSSSSS
- do:
bulk:
refresh: true
index: test
body: |
{"index":{}}
{"timestamp":"2019-10-21 00:30:04.828740"}
{"index":{}}
{"timestamp":"2019-10-21 08:30:04.828733"}
- do:
search:
index: test
body:
size: 1
sort: [{ timestamp: desc }]
- match: {hits.total.value: 2 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._source.timestamp: "2019-10-21 08:30:04.828733" }
- match: {hits.hits.0.sort: [1571646604828733000] }
# search_after with the sort
- do:
search:
index: test
body:
size: 1
sort: [{ timestamp: desc }]
search_after: [1571646604828733000]
- match: {hits.total.value: 2 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._source.timestamp: "2019-10-21 00:30:04.828740" }
- match: {hits.hits.0.sort: [1571617804828740000] }
# search_after with the formatted date
- do:
search:
index: test
body:
size: 1
sort: [{ timestamp: desc }]
search_after: ["2019-10-21 08:30:04.828733"]
- match: {hits.total.value: 2 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._index: test }
- match: {hits.hits.0._source.timestamp: "2019-10-21 00:30:04.828740" }
- match: {hits.hits.0.sort: [1571617804828740000] }
---
"Format sort values":
- requires:
cluster_features: ["gte_v7.13.0"]
reason: Format sort output is introduced in 7.13
- do:
indices.create:
index: test
body:
mappings:
properties:
timestamp:
type: date
format: yyyy-MM-dd HH:mm:ss.SSS
- do:
indices.create:
index: test_nanos
body:
mappings:
properties:
timestamp:
type: date_nanos
format: dd/MM/yyyy HH:mm:ss.SSS
- do:
bulk:
refresh: true
index: test
body: |
{"index":{}}
{"timestamp":"2021-10-13 00:30:04.828"}
{"index":{}}
{"timestamp":"2021-06-11 04:30:04.828"}
{"index":{}}
{"timestamp":"2021-02-11 08:30:04.828"}
- do:
bulk:
refresh: true
index: test_nanos
body: |
{"index":{}}
{"timestamp":"21/08/2021 03:30:04.732"}
{"index":{}}
{"timestamp":"20/05/2021 05:30:04.832"}
{"index":{}}
{"timestamp":"15/04/2021 06:30:04.821"}
- do:
search:
index: test
body:
size: 1
sort: [{timestamp: {"order" : "asc", "format": "strict_date_optional_time_nanos"}}]
- match: {hits.total.value: 3 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._source.timestamp: "2021-02-11 08:30:04.828" }
- match: {hits.hits.0.sort: ["2021-02-11T08:30:04.828Z"] }
- do:
search:
index: test
body:
size: 1
sort: [{timestamp: {"order" : "asc", "format": "strict_date_optional_time_nanos"}}]
search_after: ["2021-02-11T08:30:04.828Z"]
- match: {hits.total.value: 3 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._source.timestamp: "2021-06-11 04:30:04.828" }
- match: {hits.hits.0.sort: ["2021-06-11T04:30:04.828Z"] }
# mismatch format
- do:
catch: /failed to parse date field/
search:
index: test
body:
size: 1
sort: [{ timestamp: {"order" : "asc", "format": "yyyy-MM-dd HH:mm:ss.SSS"}}]
search_after: [ "2021-02-11T08:30:04.828Z" ]
- do:
catch: /failed to parse date field/
search:
index: test
body:
size: 1
sort: [ { timestamp: { "order": "asc", "format": "epoch_millis" } } ]
search_after: [ "2021-02-11T08:30:04.828Z" ]
- do:
search:
index: test
body:
size: 1
sort: [{timestamp: {"order" : "asc", "format": "yyyy-MM-dd | HH:mm:ss.SSS"}}]
search_after: ["2021-02-11 | 08:30:04.828"]
- match: {hits.total.value: 3 }
- length: {hits.hits: 1 }
- match: {hits.hits.0._source.timestamp: "2021-06-11 04:30:04.828" }
- match: {hits.hits.0.sort: ["2021-06-11 | 04:30:04.828"] }
# Mixed two types with numeric
- do:
search:
index: tes*
body:
size: 2
sort: [ { timestamp: { "order": "asc", "format": "strict_date_optional_time_nanos", "numeric_type": "date_nanos" } } ]
- match: { hits.total.value: 6 }
- length: { hits.hits: 2 }
- match: { hits.hits.0._index: test }
- match: { hits.hits.0._source.timestamp: "2021-02-11 08:30:04.828" }
- match: { hits.hits.0.sort: [ "2021-02-11T08:30:04.828Z" ] }
- match: { hits.hits.1._index: test_nanos }
- match: { hits.hits.1._source.timestamp: "15/04/2021 06:30:04.821" }
- match: { hits.hits.1.sort: [ "2021-04-15T06:30:04.821Z" ] }
- do:
search:
index: test*
body:
size: 2
sort: [ { timestamp: { "order": "asc", "format": "strict_date_optional_time_nanos", "numeric_type": "date" } } ]
search_after: [ "2021-04-15T06:30:04.821Z" ]
- match: { hits.total.value: 6 }
- length: { hits.hits: 2 }
- match: { hits.hits.0._index: test_nanos }
- match: { hits.hits.0._source.timestamp: "20/05/2021 05:30:04.832" }
- match: { hits.hits.0.sort: [ "2021-05-20T05:30:04.832Z" ] }
- match: { hits.hits.1._index: test }
- match: { hits.hits.1._source.timestamp: "2021-06-11 04:30:04.828" }
- match: { hits.hits.1.sort: [ "2021-06-11T04:30:04.828Z" ] }