首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elassandra: UDT列表匹配查询-没有结果

Elassandra: UDT列表匹配查询-没有结果
EN

Stack Overflow用户
提问于 2021-03-09 12:19:02
回答 1查看 115关注 0票数 1

我在用Elassandra。在卡桑德拉,我有一个UDT:

代码语言:javascript
复制
CREATE TYPE test.entity_attributes (
    attribute_key text,
    attribute_value text
);

在表中使用。

代码语言:javascript
复制
CREATE TABLE test.attributes_test (
    id text PRIMARY KEY,
    attr list<frozen<entity_attributes>>
)

我使用以下方法映射了attributes_test

代码语言:javascript
复制
curl --location --request PUT 'localhost:9200/attr_index' \
--header 'Content-Type: application/json' \
--data-raw '{
    "settings": { "keyspace": "test" },
    "mappings": {
        "attributes_test" : {
            "discover":".*"
        }
    }
}'

(抄录自邮递员)

它以映射形式返回以下内容:

代码语言:javascript
复制
{
    "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"
                }
            }
        }
    }
}

这是我在桌子上看到的:

代码语言:javascript
复制
 id | attr
----+----------------------------------------------------------------------------------------------
  2 | [{attribute_key: 'abc', attribute_value: '2'}, {attribute_key: 'def', attribute_value: '1'}]
  1 |                                               [{attribute_key: 'abc', attribute_value: '1'}]

现在的问题是,当我运行以下查询时,它不会返回任何结果。

代码语言:javascript
复制
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 -描述在嵌套对象中搜索的方法。如何在嵌套对象列表中搜索?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-10 07:31:05

这是我的疑问中的一个错误。正确的查询是:

代码语言:javascript
复制
{
    "query": {
        "nested": {
            "path": "attr",
            "query": {
                "match": {
                    "attr.attribute_key": "abc"
                }
            }
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66546737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档