strapdata / elassandra

Elassandra = Elasticsearch + Apache Cassandra
http://www.elassandra.io
Apache License 2.0
1.71k stars 198 forks source link

Elassandra: UDT List Match Query- No Results #385

Closed abhisingh1111 closed 3 years ago

abhisingh1111 commented 3 years ago

I am using Elassandra. In Cassandra, I have a UDT: CREATE TYPE test.entity_attributes ( attribute_key text, attribute_value text ); It is used in table CREATE TABLE test.attributes_test ( id text PRIMARY KEY, attr list<frozen<entity_attributes>> ) I mapped the attributes_test using: curl --location --request PUT 'localhost:9200/attr_index' \ --header 'Content-Type: application/json' \ --data-raw '{ "settings": { "keyspace": "test" }, "mappings": { "attributes_test" : { "discover":".*" } } }' (copied from postman) It returns the following as mapping: { "attr_index": { "aliases": {}, "mappings": { "attributes_test": { "properties": { "attr": { "type": "nested", "cql_udt_name": "entity_attributes", "properties": { "attribute_key": { "type": "keyword", "cql_collection": "singleton" }, "attribute_value": { "type": "keyword", "cql_collection": "singleton" } } }, "id": { "type": "keyword", "cql_collection": "singleton", "cql_partition_key": true, "cql_primary_key_order": 0 } } } }, "settings": { "index": { "keyspace": "test", "number_of_shards": "1", "provided_name": "attr_index", "creation_date": "1615291749532", "number_of_replicas": "0", "uuid": "Oua1ACLbRvCATC-kcGPoQg", "version": { "created": "6020399" } } } } } This is what I have in the table: id | attr ----+---------------------------------------------------------------------------------------------- 2 | [{attribute_key: 'abc', attribute_value: '2'}, {attribute_key: 'def', attribute_value: '1'}] 1 | [{attribute_key: 'abc', attribute_value: '1'}] The problem now is, when I run the following query, it does not return any result. curl --location --request POST 'localhost:9200/attr_index/_search' \ --header 'Content-Type: application/json' \ --data-raw '{ "query": { "match": { "attr.attribute_key": "abc" } } }' https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html - describes the way to search in nested objects. How can I search in the list of nested objects?

abhisingh1111 commented 3 years ago

Found the problem: I wasn't using the "nested" query!