kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

Search with the 'exists' keyword of Koncorde DSL does not work as expected with arrays #2347

Closed TisserantG closed 1 year ago

TisserantG commented 2 years ago

Expected Behavior

exists must work like example in : https://docs.kuzzle.io/core/2/api/koncorde-filters-syntax/clauses/#matching-array-values

Current Behavior

Following https://docs.kuzzle.io/core/2/api/koncorde-filters-syntax/clauses/#matching-array-values I do :

   const filter = { 
      query: {
        "exists": 'name.hobbies["compiler"]'
      }
    }
    const list = await this.sdk.document.search("test","t2", filter, {lang: "koncorde"} );
    console.log("list : " + JSON.stringify(list));
    const list2 = await this.sdk.document.search("test","t2", {});
    console.log("list2 : " + JSON.stringify(list2));

Result is :

list : {"hits":[],"fetched":0,"total":0}
list2 : {"hits":[{"_id":"_EpZb4ABXNxAajr4jYQ1","_score":1,"_source":{"name":{"first":"Grace","last":"Hopper","hobbies":["compiler","COBOL"]},"_kuzzle_info":{"author":"-1","createdAt":1651135581492,"updatedAt":null,"updater":null}},"collection":"t2","index":"test"}],"fetched":1,"total":1}

list and list2 would be equals.

Steps to Reproduce

1. Create collection with mapping :

{
  "dynamic": "false",
  "properties": {
    "name": {
      "properties": {
        "first": {
          "type": "keyword"
        },
        "hobbies": {
          "type": "keyword"
        },
        "last": {
          "type": "keyword"
        }
      }
    }
  }
}

2. Create document

{
  "name": {
    "first": "Grace",
    "last": "Hopper",
    "hobbies": [
      "compiler",
      "COBOL"
    ]
  }
}

3. Use filter

{ 
      query: {
        "exists": 'name.hobbies["compiler"]'
      }
    }

Idea

Query can be done with :

{
  query: {
    equals: {
      'name.hobbies': 'compiler',
    },
  },
}

So is is update documentation ( https://docs.kuzzle.io/core/2/api/koncorde-filters-syntax/clauses/ and https://github.com/kuzzleio/koncorde/wiki/Filter-Syntax ) may be enough.

OlivierCavadenti commented 2 years ago

Cases are not tested here : https://github.com/kuzzleio/kuzzle/blob/fec478770d8ce0be0a46571888292d5421433b72/test/service/storage/queryTranslator.test.js Don't forget to add tests.