apache / couchdb

Seamless multi-master syncing database with an intuitive HTTP/JSON API, designed for reliability
https://couchdb.apache.org/
Apache License 2.0
6.26k stars 1.03k forks source link

Nouveau: Emitting multiple indexes per field per doc only returns the last indexed value when doing `{"store": true}` #5285

Closed espy closed 1 month ago

espy commented 1 month ago

Description

Assume I have many products with an array of colors each. I can index('string', 'color', color[i]) each color from each array individually for a facet search/count, and that works fine, they’re counted correctly. However, if I return the indexed fields with {"store": true}, only the last emitted color per product is returned in the fields section.

Steps to Reproduce

In a CouchDB with activated Nouveau, with a running Nouveau server:

  1. Have some docs with an array of values, eg. "colors": ["mauve", "fuchsia", "ennui"]
  2. Add a Nouveau string index for that key (newlines for readability only):
    {
      "_id": "_design/nouveau_example",
      "nouveau": {
        "facets": {
          "index": "function(doc) {
            if (doc.colors) { 
              doc.colors.forEach((color) => 
                index('string', 'color', color, {'store': true})
              )
            }
          }"
        }
      }
    }
  3. Send a counts query :

    /_design/nouveau_example/_nouveau/facets?q=*:*&counts=["color"]
  4. This returns:
    • For the doc above:
      "fields": {
      "color": "ennui"
      }
    • At the end in the counts:
      "counts": {
      "color": {
        "mauve": 1,
        "fuchsia": 1,
        "ennui": 1
      }
      }

Expected Behaviour

Somehow get all colors per doc back in fields.

Your Environment

{
  "couchdb":"Welcome",
  "version":"3.4.1",
  "git_sha":"f504e38a5",
  "uuid":"4e36c505782b7068ead9895902c5f07d",
  "features":[
    "nouveau",
    "access-ready",
    "partitioned",
    "pluggable-storage-engines",
    "reshard",
    "scheduler"
  ],
  "vendor":{"name":"The Apache Software Foundation"}
}