Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

6.7 KB
Raw Blame
setup:
  - do:
      indices.create:
        index: my-index
        body:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              users:
                type: nested

  - do:
      index:
        index:  my-index
        id:     "1"
        refresh: true
        body: |
          {
            "group" : "fans",
            "users" : [
              {
                "first" : "John",
                "last" :  "Smith"
              },
              {
                "first" : "Alice",
                "last" :  "White"
              }
            ]
          }

  - do:
      index:
        index:  my-index
        id:     "2"
        refresh: true
        body: |
          {
            "group" : "fans",
            "users" : [
              {
                "first" : "Mark",
                "last" :  "Doe"
              }
            ]
          }

---
"top_hits aggregation with nested documents":
  - do:
      search:
        rest_total_hits_as_int: true
        index: my-index
        body:
          aggs:
            to-users:
              nested:
                path: users
              aggs:
                users:
                  top_hits:
                    sort: "users.last.keyword"

  - match: { hits.total: 2 }
  - length: { aggregations.to-users.users.hits.hits: 3 }
  - match: { aggregations.to-users.users.hits.hits.0._id: "2" }
  - match: { aggregations.to-users.users.hits.hits.0._index: my-index }
  - match: { aggregations.to-users.users.hits.hits.0._nested.field: users }
  - match: { aggregations.to-users.users.hits.hits.0._nested.offset: 0 }
  - match: { aggregations.to-users.users.hits.hits.1._id: "1" }
  - match: { aggregations.to-users.users.hits.hits.1._index: my-index }
  - match: { aggregations.to-users.users.hits.hits.1._nested.field: users }
  - match: { aggregations.to-users.users.hits.hits.1._nested.offset: 0 }
  - match: { aggregations.to-users.users.hits.hits.2._id: "1" }
  - match: { aggregations.to-users.users.hits.hits.2._index: my-index }
  - match: { aggregations.to-users.users.hits.hits.2._nested.field: users }
  - match: { aggregations.to-users.users.hits.hits.2._nested.offset: 1 }

---
"top_hits aggregation with nested documents and disabled _source":
  - requires:
      cluster_features: ["gte_v7.10.2"]
      reason: "bug fix introduced in 7.10.2"
  - do:
      indices.create:
        index: disabled-source
        body:
          settings:
            number_of_shards: 1
          mappings:
            _source:
              enabled: false
            properties:
              users:
                type: nested

  - do:
      index:
        index:  disabled-source
        id:     "1"
        refresh: true
        body:
          users:
            - first: "John"
              last:  "Smith"

  - do:
      search:
        index: disabled-source
        rest_total_hits_as_int: true
        body:
          aggs:
            to-users:
              nested:
                path: users
              aggs:
                users:
                  top_hits: {}

  - match: { hits.total: 1 }
  - length: { aggregations.to-users.users.hits.hits: 1 }
  - match: { aggregations.to-users.users.hits.hits.0._id: "1" }
  - match: { aggregations.to-users.users.hits.hits.0._index: disabled-source }
  - match: { aggregations.to-users.users.hits.hits.0._nested.field: users }
  - match: { aggregations.to-users.users.hits.hits.0._nested.offset: 0 }
  - is_false: aggregations.to-users.users.hits.hits.0._source

---
"top_hits aggregation with sequence numbers":

  - do:
      search:
        index: my-index
        rest_total_hits_as_int: true
        body:
          aggs:
            groups:
              terms:
                field: group.keyword
              aggs:
                users:
                  top_hits:
                    sort:
                      users.last.keyword:
                        nested:
                          path: users
                    seq_no_primary_term: true

  - match: { hits.total: 2 }
  - length: { aggregations.groups.buckets.0.users.hits.hits: 2 }
  - match: { aggregations.groups.buckets.0.users.hits.hits.0._id: "2" }
  - match: { aggregations.groups.buckets.0.users.hits.hits.0._index: my-index }
  - gte: { aggregations.groups.buckets.0.users.hits.hits.0._seq_no: 0 }
  - gte: { aggregations.groups.buckets.0.users.hits.hits.0._primary_term: 1 }
  - match: { aggregations.groups.buckets.0.users.hits.hits.1._id: "1" }
  - match: { aggregations.groups.buckets.0.users.hits.hits.1._index: my-index }
  - gte: { aggregations.groups.buckets.0.users.hits.hits.1._seq_no: 0 }
  - gte: { aggregations.groups.buckets.0.users.hits.hits.1._primary_term: 1 }

---
"nested top_hits aggregation with query inner_hits":
  - requires:
      cluster_features: ["nested_agg_top_hits_with_inner_hits"]
      reason: "Fix for nested aggregation top_hits with query inner_hits"
  - do:
      indices.create:
        index: nested-inner-hits-test
        body:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              nested_item:
                type: nested
                properties:
                  title:
                    type: text
                  content:
                    type: text
                  number:
                    type: long

  - do:
      index:
        index: nested-inner-hits-test
        id: "1"
        refresh: true
        body:
          nested_item:
            - title: "foo"
            - title: "foobar"
              content: "foobar foobar"
            - title: "baz"
              content: "foobar"
              number: 2

  - do:
      search:
        index: nested-inner-hits-test
        rest_total_hits_as_int: true
        body:
          query:
            nested:
              path: nested_item
              inner_hits: {}
              query:
                match_all: {}
          aggs:
            nested_item:
              nested:
                path: nested_item
              aggs:
                top_nested:
                  top_hits: {}

  - match: { hits.total: 1 }
  - length: { hits.hits.0.inner_hits.nested_item.hits.hits: 3 }
  - match: { aggregations.nested_item.top_nested.hits.total: 3 }
  - length: { aggregations.nested_item.top_nested.hits.hits: 3 }
  - match: { aggregations.nested_item.top_nested.hits.hits.0._nested.field: nested_item }
  - match: { aggregations.nested_item.top_nested.hits.hits.0._nested.offset: 0 }
  - match: { aggregations.nested_item.top_nested.hits.hits.1._nested.field: nested_item }
  - match: { aggregations.nested_item.top_nested.hits.hits.1._nested.offset: 1 }
  - match: { aggregations.nested_item.top_nested.hits.hits.2._nested.field: nested_item }
  - match: { aggregations.nested_item.top_nested.hits.hits.2._nested.offset: 2 }