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.

13.9 KB
Raw Blame
---
"Default index":
  - do:
      indices.create:
          index:  goodbad
          body:
            settings:
                number_of_shards: "1"
            mappings:
                properties:
                    text:
                        type: text
                        fielddata: true
                    class:
                        type: keyword

  - do:
      index:
          index:  goodbad
          id:     "1"
          body:   { text: "good", class: "good" }
  - do:
      index:
          index:  goodbad
          id:     "2"
          body:   { text: "good", class: "good" }
  - do:
      index:
          index:  goodbad
          id:     "3"
          body:   { text: "bad", class: "bad" }
  - do:
      index:
          index:  goodbad
          id:     "4"
          body:   { text: "bad", class: "bad" }
  - do:
      index:
          index:  goodbad
          id:     "5"
          body:   { text: "good bad", class: "good" }
  - do:
      index:
          index:  goodbad
          id:     "6"
          body:   { text: "good bad", class: "bad" }
  - do:
      index:
          index:  goodbad
          id:     "7"
          body:   { text: "bad", class: "bad" }



  - do:
      indices.refresh:
        index: [goodbad]

  - do:
      search:
        rest_total_hits_as_int: true
        index: goodbad

  - match: {hits.total: 7}

  - do:
      search:
        rest_total_hits_as_int: true
        index: goodbad
        body: {"aggs": {"class": {"terms": {"field": "class"},"aggs": {"sig_terms": {"significant_terms": {"field": "text"}}}}}}

  - match: {aggregations.class.buckets.0.sig_terms.buckets.0.key: "bad"}
  - match: {aggregations.class.buckets.1.sig_terms.buckets.0.key: "good"}

---
"Test background filter count":
  - requires:
      cluster_features: ["gte_v7.15.0"]
      reason: bugfix introduced in 7.15.0

  - do:
      indices.create:
        index:  goodbad
        body:
          settings:
            number_of_shards: "1"
          mappings:
            properties:
              text:
                type: text
                fielddata: true
              class:
                type: keyword
  - do:
      indices.create:
        index: goodbad-2
        body:
          settings:
            number_of_shards: "1"
          mappings:
            properties:
              text:
                type: text
                fielddata: true
              class:
                type: keyword

  - do:
      index:
        index: goodbad-2
        id: "1"
        body: { class: "bad" }
  - do:
      index:
        index: goodbad-2
        id: "2"
        body: { class: "bad" }

  - do:
      index:
        index:  goodbad
        id:     "1"
        body:   { text: "good", class: "good" }
  - do:
      index:
        index:  goodbad
        id:     "2"
        body:   { text: "good", class: "good" }
  - do:
      index:
        index:  goodbad
        id:     "3"
        body:   { text: "bad", class: "bad" }
  - do:
      index:
        index:  goodbad
        id:     "4"
        body:   { text: "bad", class: "bad" }

  - do:
      indices.refresh:
        index: [goodbad, goodbad-2]

  - do:
      search:
        rest_total_hits_as_int: true
        index: goodbad*

  - match: {hits.total: 6}

  - do:
      search:
        index: goodbad*
        body: {"aggs": {"sig_terms": {"significant_terms": {"field": "text", "background_filter": {"bool": {"filter": [{"term": {"class": "good" }}]}}}}}}
  - match: { aggregations.sig_terms.bg_count: 2 }

---
"Test background filter count as sub - global ords":
  - requires:
      capabilities:
        - method: POST
          path: /_search
          capabilities: [ significant_terms_background_filter_as_sub ]
      test_runner_features: capabilities
      reason: "bug fix"

  - do:
      indices.create:
        index:  goodbad
        body:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              text:
                type: keyword
              class:
                type: keyword
  - do:
      indices.create:
        index: goodbad-2
        body:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              text:
                type: keyword
              class:
                type: keyword

  - do:
      index:
        index: goodbad-2
        id: "1"
        body: { group: 1, class: "bad" }
  - do:
      index:
        index: goodbad-2
        id: "2"
        body: { group: 1, class: "bad" }

  - do:
      index:
        index:  goodbad
        id:     "1"
        body:   { group: 1, text: "good", class: "good" }
  - do:
      index:
        index:  goodbad
        id:     "2"
        body:   { group: 1, text: "good", class: "good" }
  - do:
      index:
        index:  goodbad
        id:     "3"
        body:   { group: 1, text: "bad", class: "bad" }
  - do:
      index:
        index:  goodbad
        id:     "4"
        body:   { group: 2, text: "bad", class: "bad" }

  - do:
      indices.refresh:
        index: [goodbad, goodbad-2]

  - do:
      search:
        rest_total_hits_as_int: true
        index: goodbad*
  - match: {hits.total: 6}

  - do:
      search:
        index: goodbad*
        body:
          aggs:
            group:
              range:
                field: group
                ranges:
                  # Having many ranges helps catch an issue building no hits buckets
                  - to: 1
                  - from: 1
                    to: 2
                  - from: 2
                    to: 3
                  - from: 3
                    to: 4
                  - from: 4
                    to: 5
                  - from: 5
                    to: 6
              aggs:
                sig_terms:
                  significant_terms:
                    execution_hint: global_ordinals
                    field: text
                    background_filter:
                      bool:
                        filter: [{term: {class: good }}]
  - match: { aggregations.group.buckets.0.key: "*-1.0" }
  - match: { aggregations.group.buckets.0.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.0.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.1.key: "1.0-2.0" }
  - match: { aggregations.group.buckets.1.sig_terms.doc_count: 5 }
  - match: { aggregations.group.buckets.1.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.2.key: "2.0-3.0" }
  - match: { aggregations.group.buckets.2.sig_terms.doc_count: 1 }
  - match: { aggregations.group.buckets.2.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.3.key: "3.0-4.0" }
  - match: { aggregations.group.buckets.3.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.3.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.4.key: "4.0-5.0" }
  - match: { aggregations.group.buckets.4.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.4.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.5.key: "5.0-6.0" }
  - match: { aggregations.group.buckets.5.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.5.sig_terms.bg_count: 2 }

---
"Test background filter count as sub - map":
  - requires:
      capabilities:
        - method: POST
          path: /_search
          capabilities: [ significant_terms_background_filter_as_sub ]
      test_runner_features: capabilities
      reason: "bug fix"

  - do:
      indices.create:
        index:  goodbad
        body:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              text:
                type: keyword
              class:
                type: keyword
  - do:
      indices.create:
        index: goodbad-2
        body:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              text:
                type: keyword
              class:
                type: keyword

  - do:
      index:
        index: goodbad-2
        id: "1"
        body: { group: 1, class: "bad" }
  - do:
      index:
        index: goodbad-2
        id: "2"
        body: { group: 1, class: "bad" }

  - do:
      index:
        index:  goodbad
        id:     "1"
        body:   { group: 1, text: "good", class: "good" }
  - do:
      index:
        index:  goodbad
        id:     "2"
        body:   { group: 1, text: "good", class: "good" }
  - do:
      index:
        index:  goodbad
        id:     "3"
        body:   { group: 1, text: "bad", class: "bad" }
  - do:
      index:
        index:  goodbad
        id:     "4"
        body:   { group: 2, text: "bad", class: "bad" }

  - do:
      indices.refresh:
        index: [goodbad, goodbad-2]

  - do:
      search:
        rest_total_hits_as_int: true
        index: goodbad*
  - match: {hits.total: 6}

  - do:
      search:
        index: goodbad*
        body:
          aggs:
            group:
              range:
                field: group
                ranges:
                  # Having many ranges helps catch an issue building no hits buckets
                  - to: 1
                  - from: 1
                    to: 2
                  - from: 2
                    to: 3
                  - from: 3
                    to: 4
                  - from: 4
                    to: 5
                  - from: 5
                    to: 6
              aggs:
                sig_terms:
                  significant_terms:
                    execution_hint: map
                    field: text
                    background_filter:
                      bool:
                        filter: [{term: {class: good }}]
  - match: { aggregations.group.buckets.0.key: "*-1.0" }
  - match: { aggregations.group.buckets.0.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.0.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.1.key: "1.0-2.0" }
  - match: { aggregations.group.buckets.1.sig_terms.doc_count: 5 }
  - match: { aggregations.group.buckets.1.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.2.key: "2.0-3.0" }
  - match: { aggregations.group.buckets.2.sig_terms.doc_count: 1 }
  - match: { aggregations.group.buckets.2.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.3.key: "3.0-4.0" }
  - match: { aggregations.group.buckets.3.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.3.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.4.key: "4.0-5.0" }
  - match: { aggregations.group.buckets.4.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.4.sig_terms.bg_count: 2 }
  - match: { aggregations.group.buckets.5.key: "5.0-6.0" }
  - match: { aggregations.group.buckets.5.sig_terms.doc_count: 0 }
  - match: { aggregations.group.buckets.5.sig_terms.bg_count: 2 }

---
"IP test":
  - do:
      indices.create:
          index:  ip_index
          body:
            mappings:
                properties:
                    ip:
                        type: ip

  - do:
      index:
          index:  ip_index
          id:     "1"
          body:   { ip: "::1" }
  - do:
      index:
          index:  ip_index
          id:     "2"
          body:   { }

  - do:
      indices.refresh: {}

  - do:
      search:
        rest_total_hits_as_int: true
        body: { "query" : { "exists" : { "field" : "ip" } }, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "min_doc_count" : 1 } } } }

  - match: { hits.total: 1 }

  - length: { aggregations.ip_terms.buckets: 1 }

  - match: { aggregations.ip_terms.buckets.0.key: "::1" }

  - is_false: aggregations.ip_terms.buckets.0.key_as_string

  - match: { aggregations.ip_terms.buckets.0.doc_count: 1 }

  - do:
      search:
        rest_total_hits_as_int: true
        body: { "query" : { "exists" : { "field" : "ip" } }, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "min_doc_count" : 1, "include" : [ "::1" ] } } } }

  - match: { hits.total: 1 }

  - length: { aggregations.ip_terms.buckets: 1 }

  - match: { aggregations.ip_terms.buckets.0.key: "::1" }

  - do:
      search:
        rest_total_hits_as_int: true
        body: { "query" : { "exists" : { "field" : "ip" } }, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "min_doc_count" : 1, "exclude" : [ "::1" ] } } } }

  - match: { hits.total: 1 }

  - length: { aggregations.ip_terms.buckets: 0 }

  - do:
      catch: /Aggregation \[ip_terms\] cannot support regular expression style include\/exclude settings as they can only be applied to string fields\. Use an array of values for include\/exclude clauses/
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "ip_terms" : { "significant_terms" : { "field" : "ip", "exclude" :  "127.*"  } } } }

---
'Misspelled fields get "did you mean"':
  - requires:
      cluster_features: ["gte_v7.7.0"]
      reason: introduced in 7.7.0
  - do:
      catch: /\[significant_terms\] unknown field \[jlp\] did you mean \[jlh\]\?/
      search:
          body:
            aggs:
              foo:
                significant_terms:
                  field: foo
                  jlp: {}

---
"Test alias background filter":
  - requires:
      cluster_features: ["gte_v8.4.0"]
      reason: fixed in 8.4

  - do:
      indices.create:
        index:  test_index
        body:
          mappings:
            properties:
              field1:
                type: keyword
              field2:
                type: keyword

  - do:
      indices.put_alias:
        index: test_index
        name: test_alias
        body: {"filter": {"bool": {"filter": [{"term": {"field2": "foo"}}]}}}
  - do:
      index:
        index: test_index
        id: "1"
        body: { "field1" : "1", "field2": "foo" }

  - do:
      index:
        index: test_index
        id: "2"
        body: { "field1": "2", "field2": "bar" }

  - do:
      index:
        index: test_index
        id: "3"
        body: { "field1": "3", "field2": "foo" }

  - do:
      indices.refresh: {}

  - do:
      search:
        index: test_alias
        body: {"aggs": {"sig_terms": {"significant_terms": {"field": "field1"}}}}
  - match: { aggregations.sig_terms.bg_count: 2 }