Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Indexing 如何为Couchbase中的嵌入式对象创建索引?_Indexing_Couchbase_N1ql - Fatal编程技术网

Indexing 如何为Couchbase中的嵌入式对象创建索引?

Indexing 如何为Couchbase中的嵌入式对象创建索引?,indexing,couchbase,n1ql,Indexing,Couchbase,N1ql,我的桶里有一百万份文件 我要运行此查询: SELECT * FROM bucket WHERE type = 'toy' AND material = 'plastic' AND color = 'red' AND weight = '200gr' AND height = '5cm' AND width = '15cm' “属性”是嵌入在文档中的对象 例如: “类型”:“玩具”,“其他键”:“其他值”,“其他键”:“其他” 值“,“属性”:{“材料”:“塑料”, “颜色”:“红色”,“重量”

我的桶里有一百万份文件

我要运行此查询:

SELECT * FROM bucket WHERE type = 'toy' AND material = 'plastic' AND color = 'red' AND weight = '200gr' AND height = '5cm' AND width = '15cm'
“属性”是嵌入在文档中的对象

例如:

“类型”:“玩具”,“其他键”:“其他值”,“其他键”:“其他” 值“,
“属性”:{
“材料”:“塑料”,

“颜色”:“红色”,
“重量”:“200gr”,
“高度”:“5cm”,
“宽度”:“15cm”
}
“其他键”:“其他值”、
“其他键”: “其他价值”


如何在Query Workbench中创建索引以获得尽可能快的响应时间?

假设您有如下文档:

{
    "type": "toy",
        "attributes": {
        "material": "plastic",
        "color": "red",
        "weight": "200gr",
        "height": "5cm",
        "width": "15cm"
    }
}
您的查询如下所示:

SELECT * FROM `test` t WHERE t.type = 'toy' AND t.attributes.material = 'plastic' AND t.attributes.color = 'red'AND t.attributes.weight = '200gr' AND t.attributes.height = '5cm' AND t.attributes.width = '15cm'
它的索引将类似于此:

create index toysIndex on `test`(type, attributes.material, attributes.color, attributes.weight, attributes.height, attributes.width  ) USING GSI; 

deniswsrosa的建议肯定会奏效,但您可以通过将类型规范移动到索引的WHERE子句中来对其进行改进。这样,这些字段的索引将只包括“toy”类型的对象;其他类型的对象将不会被索引。这将使索引变得更小,因为它更具体。type=“toy”子句仍将在使用索引时予以考虑

像这样:

create index toysIndex on test(attributes.material, attributes.color,
attributes.weight, attributes.height, attributes.width  ) 
where type = 'toy'; 
请注意,您不需要在“test”周围打勾。此外,GSI索引是默认索引