{"id":8407,"date":"2020-04-13T00:33:48","date_gmt":"2020-04-13T07:33:48","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=8407"},"modified":"2025-06-13T17:21:46","modified_gmt":"2025-06-14T00:21:46","slug":"flexible-query-indexing-for-flexible-json-model","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/flexible-query-indexing-for-flexible-json-model\/","title":{"rendered":"Consulta e indexa\u00e7\u00e3o flex\u00edveis para o modelo JSON flex\u00edvel."},"content":{"rendered":"<blockquote>\n<h4>Use o N1QL quando estiver em uma situa\u00e7\u00e3o dif\u00edcil com o JSON. - Conf\u00facio<\/h4>\n<\/blockquote>\n<p>Para o modelo de dados JSON, a recomenda\u00e7\u00e3o \u00e9 pensar nas cole\u00e7\u00f5es como tabelas, no documento JSON como linhas desnormalizadas e nos nomes de campo como colunas - aproximadamente. Tudo isso \u00e9 v\u00e1lido em bancos de dados como o Couchbase e o MongoDB quando as recomenda\u00e7\u00f5es s\u00e3o seguidas \u00e0 risca. <span style=\"font-weight: 400\">H\u00e1 muitos motivos pelos quais os usu\u00e1rios n\u00e3o seguem simplesmente esse modelo de par de valores-chave <\/span><i><span style=\"font-weight: 400\">o tempo todo. <\/span><\/i><span style=\"font-weight: 400\">Aqui est\u00e3o os principais motivos.\u00a0<\/span><\/p>\n<ol>\n<li style=\"list-style-type: none\">\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">JSON \u00e9 <a href=\"https:\/\/dzone.com\/articles\/keep-calm-and-json\">muito prolixo<\/a>.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Voc\u00ea deseja converter uma estrutura de dados de mapa\/hashmap em que as chaves s\u00e3o din\u00e2micas.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Dados de s\u00e9rie temporal quando os nomes de campo s\u00e3o geralmente carimbos de data\/hora codificados.<\/span><\/li>\n<li style=\"font-weight: 400\"><a href=\"https:\/\/dzone.com\/articles\/keep-calm-and-json\"><span style=\"font-weight: 400\">Codifica\u00e7\u00e3o baseada em dicion\u00e1rio<\/span><\/a><\/li>\n<li>Os formatos e padr\u00f5es de documentos existentes n\u00e3o permitem o redesenho<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Se o seu banco de dados e a linguagem de consulta n\u00e3o lidarem com a situa\u00e7\u00e3o, voc\u00ea ter\u00e1 que passar por um redesenho elaborado.  Al\u00e9m de simplesmente acessar as informa\u00e7\u00f5es, <span style=\"font-weight: 400\">Como voc\u00ea torna as consultas em JSON eficientes quando voc\u00ea <\/span><span style=\"font-weight: 400\">n\u00e3o sabe nem mesmo o nome do campo que voc\u00ea precisa indexar? <\/span><span style=\"font-weight: 400\"> Felizmente, o Couchbase N1QL tem uma variedade de recursos de consulta e \u00edndice para lidar tamb\u00e9m com metadados flex\u00edveis. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Vamos considerar esses casos de uso.<\/span><\/p>\n<h4>Caso de uso 1: transforma\u00e7\u00e3o de valor.<\/h4>\n<p>Aqui est\u00e1 um exemplo de documento JSON.<\/p>\n<pre title=\"Exemplo de documento JSON\" class=\"theme:dark-terminal font-size:17 line-height:20 lang:js decode:true\">{\r\n    \"cname\": \"Jane Smith\",\r\n    \"dob\" : \"1990-01-30\",\r\n    \"phones\" : [\r\n    \"+1 510-523-3529\", \"+1 650-392-4923\"\r\n    ],\r\n    \"billing\": [\r\n      {\r\n        \"type\": \"visa\",\r\n        \"cardnum\": \"5827-2842-2847-3909\",\r\n        \"expiry\" (expira\u00e7\u00e3o): \"2019-03\"\r\n      },\r\n      {\r\n        \"type\" (tipo): \"master\",\r\n        \"cardnum\": \"6274-2542-5847-3949\",\r\n        \"expiry\" (expira\u00e7\u00e3o): \"2018-12\"\r\n      }\r\n    ]\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400\">O modelo de dados JSON \u00e9 descrito simplesmente como um conjunto de pares chave-valor.  Cada chave \u00e9 uma cadeia de caracteres, exclusiva naquele n\u00edvel da hierarquia, e os valores podem ser escalares, objetos ou matrizes.  Uma defini\u00e7\u00e3o rigorosa pode ser lida <\/span><a href=\"https:\/\/tools.ietf.org\/id\/draft-handrews-json-schema-00.html\"><span style=\"font-weight: 400\">aqui<\/span><\/a><span style=\"font-weight: 400\">. O JSON tamb\u00e9m \u00e9 autodescritivo, o que o torna flex\u00edvel para um <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/couchbase-for-oracle-developers-part-4-data-types\/\"><span style=\"font-weight: 400\">modelo de documento de banco de dados<\/span><\/a><span style=\"font-weight: 400\">. Nem todo cliente precisa ter um n\u00famero fixo de n\u00fameros de telefone, carros ou qualquer outro tipo de atributo.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">As mesmas informa\u00e7\u00f5es acima podem ser reorganizadas como o JSON abaixo sem perda de informa\u00e7\u00f5es, mas alguns c\u00f3digos impl\u00edcitos<\/span><\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:2 lang:js decode:true\">{\r\n    \"Jane Smith\": \"1990-01-30\",\r\n    \"home\": \"+1 510-523-3529\",\r\n    \"escrit\u00f3rio\": \"+1 650-392-4923\",\r\n    \"Billing\" (Faturamento): [\r\n      {\r\n        \"visa\": \"5827-2842-2847-3909\",\r\n        \"expiry\" (expira\u00e7\u00e3o): \"2019-03\"\r\n      },\r\n      {\r\n        \"master\": \"6274-2542-5847-3949\",\r\n        \"expiry\" (expira\u00e7\u00e3o): \"2018-12\"\r\n      }\r\n    ]\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Isso \u00e9 muito bom se voc\u00ea estiver simplesmente colocando e definindo o documento.  N\u00e3o importa qual seja a estrutura do JSON. Basta arrastar o documento para frente e para tr\u00e1s.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Agora, vamos ver como isso afeta a consulta.<\/span><\/p>\n<p><span class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:1 whitespace-after:1 lang:mysql decode:true crayon-inline\">Q1: SELECT * FROM customers WHERE cxname = \u201cJane Smith\u201d; <\/span><\/p>\n<p><span style=\"font-weight: 400\">Com o novo modelo JSON, n\u00e3o h\u00e1 um nome de campo chamado <strong>cxname<\/strong>\u00a0aqui.<\/span><\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:1 whitespace-after:1 lang:mysql decode:true\">Q2: SELECT p FROM people p\r\nWHERE ANY o IN object_names(p) SATISFIES o = \"Jane Smith\" END<\/pre>\n<p><span style=\"font-weight: 400\">O que a magia do <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/objectfun.html#object_pairsexpression\"><span style=\"font-weight: 400\">object_pairs()<\/span><\/a><span style=\"font-weight: 400\"> function?  Ela transforma os pares JSON {\"key\": \"value\"} em uma matriz de pares nome-valor.  Veja um exemplo.<\/span><\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 top-margin:20 whitespace-before:1 whitespace-after:1 lang:mysql decode:true\">SELECT OBJECT_NAMES({\"Jane Smith\": \"1990-01-30\", \"home\": \"+1 510-523-3529\"})\r\n\r\n    \"$1\": [\r\n      \"Jane Smith\",\r\n      \"home\"\r\n    ]\r\n  }\r\n<\/pre>\n<p>A fun\u00e7\u00e3o OBJECT_NAMES() extrai a chave (aqui \"Jane Smith\") e retorna como um valor, que pode ser indexado. Como a fun\u00e7\u00e3o retorna n\u00e3o apenas um valor, mas uma matriz de \"nomes de chaves\" como valores, voc\u00ea precisa criar um \u00edndice de matriz.\u00a0 <span style=\"font-weight: 400\">As consultas Q1 e Q2 fazem o mesmo trabalho para o respectivo modelo de dados.  Por\u00e9m, precisamos que cada uma dessas consultas seja executada em milissegundos.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Para o Q1, simplesmente criamos o \u00edndice em cxname.<\/span><\/p>\n<p><span class=\"theme:dark-terminal font-size:17 line-height:20 lang:mysql decode:true crayon-inline\">CREATE INDEX ix_cxname ON customers(cxname)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Para o Q2,\u00a0\u00a0<\/span><\/p>\n<p><span class=\"theme:dark-terminal font-size:17 line-height:20 lang:mysql decode:true crayon-inline\">CREATE INDEX ix_people ON people(DISTINCT OBJECT_NAMES(self))<\/span><\/p>\n<p>Com esse \u00edndice, para o Q2, voc\u00ea obter\u00e1 um plano que usa o \u00edndice.<\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:1 whitespace-after:1 lang:js decode:true\">        {\r\n            \"#operator\": \"DistinctScan\",\r\n            \"scan\": {\r\n                \"#operator\": \"IndexScan3\",\r\n                \"as\": \"p\",\r\n                \"cardinality\": 1,\r\n                \"cost\" (custo): 0.273,\r\n                \"index\" (\u00edndice): \"ix_people\",\r\n                \"index_id\": \"4a2df8dd85543aa4\",\r\n                \"index_projection\": {\r\n                    \"primary_key\": true\r\n                },\r\n                \"keyspace\": \"people\" (pessoas),\r\n                \"namespace\": \"default\",\r\n                \"spans\": [\r\n                    {\r\n                        \"exact\": true,\r\n                        \"range\" (intervalo): [\r\n                            {\r\n                                \"high\": \"\\\"Jane Smith\\\"\",\r\n                                \"inclusion\" (inclus\u00e3o): 3,\r\n                                \"low\" (baixo): \"\\\"Jane Smith\\\"\"\r\n                            }\r\n                        ]\r\n                    }\r\n                ],<\/pre>\n<p>&nbsp;<\/p>\n<h4>Caso de uso 2: nomes de chaves din\u00e2micas.<\/h4>\n<p>Este caso de uso foi extra\u00eddo do <span style=\"font-weight: 400\">Couchbase <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/forums\/t\/indexing-object-with-dynamic-keys-within-a-document\/24526\/2\/\"><span style=\"font-weight: 400\">post do f\u00f3rum.<\/span><\/a><\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:2 lang:js decode:true\">{\r\n    \"id\": \"05a9b954-bdee-4d7f-9715-8e9e08f8cb75\",\r\n    \"type\": \"article\",\r\n    \"translations\": {\r\n        \"en\": \"Hello\",\r\n        \"de\": \"Hallo\",\r\n        \"fr\": \"Bonjour\",\r\n        \"es\": \"Hola\"\r\n    }\r\n}<\/pre>\n<p><span style=\"font-weight: 400\"><strong>Pergunta:<\/strong> <\/span><span style=\"font-weight: 400\">Qual seria a melhor maneira de indexar os valores dentro de <\/span><strong>tradu\u00e7\u00f5es<\/strong><span style=\"font-weight: 400\"><strong> dinamicamente<\/strong>? Ou seja, um \u00edndice gen\u00e9rico que indexa todas as chaves dentro do <\/span><span style=\"font-weight: 400\">tradu\u00e7\u00f5es<\/span><span style=\"font-weight: 400\"> objeto. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Se a necessidade for simplesmente consultar documentos em ingl\u00eas o tempo todo, para <\/span><span style=\"font-weight: 400\">consultar todos os documentos que tenham <\/span><span style=\"font-weight: 400\">translations.en = \"Hello\" (Ol\u00e1)<\/span><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Se estiver sempre procurando por tradu\u00e7\u00f5es para o ingl\u00eas, basta criar o \u00edndice em transactions.en.<\/span><\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:1 whitespace-after:1 lang:mysql decode:true\">CREATE INDEX ix_tren ON info(translations.en);\r\nSELECT * FROM info WHERE translation.en = \"Hello\";<\/pre>\n<p>Se as chaves forem din\u00e2micas, voc\u00ea n\u00e3o sabe qual linguagem espec\u00edfica estar\u00e1 nos dados e quais podem ser consultadas, ent\u00e3o \u00e9 preciso torn\u00e1-las din\u00e2micas.<\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:1 whitespace-after:1 lang:mysql decode:true\">\/* Consulta *\/\r\nSELECIONAR *\r\nFROM info\r\n    WHERE ANY v IN OBJECT_PAIRS(translations)\r\n            SATISFIES [v.name,v.val] = [\"en\", \"Hello\"]\r\n        END\r\n\r\n\/* \u00cdndice *\/\r\nCREATE INDEX ix_infoname ON info (\r\n    DISTINCT ARRAY [v.name, v.val ]\r\n    FOR v IN OBJECT_PAIRS(translations) END\r\n)<\/pre>\n<p>Aqui est\u00e1 a explica\u00e7\u00e3o para verificar se o \u00edndice \u00e9 de fato coletado e se os predicados s\u00e3o enviados para a varredura do \u00edndice.<\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 whitespace-before:2 whitespace-after:2 lang:js decode:true\">        {\r\n            \"#operator\": \"DistinctScan\",\r\n            \"scan\": {\r\n                \"#operator\": \"IndexScan3\",\r\n                \"cardinality\" (cardinalidade): 0.5,\r\n                \"cost\" (custo): 0.1665,\r\n                \"index\" (\u00edndice): \"ix_infoname\",\r\n                \"index_id\": \"bebbfd22a022fb75\",\r\n                \"index_projection\": {\r\n                    \"primary_key\": true\r\n                },\r\n                \"keyspace\": \"info\",\r\n                \"namespace\": \"default\",\r\n                \"spans\": [\r\n                    {\r\n                        \"exact\": true,\r\n                        \"range\" (intervalo): [\r\n                            {\r\n                                \"high\" (alto): \"[\\\"en\\\", \\\"Hello\\\"]\",\r\n                                \"inclusion\" (inclus\u00e3o): 3,\r\n                                \"low\" (baixo): \"[\\\"en\\\", \\\"Hello\\\"]\"\r\n                            }\r\n                        ]\r\n                    }\r\n                ],\r\n                \"using\": \"gsi\"\r\n            }\r\n        },<\/pre>\n<p>N\u00e3o se preocupe se a defini\u00e7\u00e3o do \u00edndice parecer um pouco mais complicada do que o normal.  O Index Advisor o ajudar\u00e1.<\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 wrap:true whitespace-before:2 whitespace-after:2 lang:mysql decode:true\">ADVISE SELECT *\r\n       FROM info\r\n       WHERE ANY v IN OBJECT_PAIRS(translations)\r\n                 SATISFIES [v.name,v.val] = [\"en\", \"Hello\"]\r\n       END\r\n\r\n\r\n{\r\n    \"index_statement\": \"CREATE INDEX adv_DISTINCT_object_pairs_translations_name_val ON `info`(DISTINCT ARRAY [`v`.`name`, `v`.`val`] FOR v in object_pairs((`translations`)) END)\",\r\n    \"keyspace_alias\": \"info\",\r\n    \"recommending_rule\": \"As chaves de \u00edndice seguem a ordem dos tipos de predicado: 2. equality\/null\/missing.\"\r\n}<\/pre>\n<p>Voc\u00ea pode at\u00e9 mesmo adicionar express\u00f5es em cima de cada express\u00e3o que estiver avaliando.<\/p>\n<pre class=\"theme:dark-terminal font-size:17 line-height:20 wrap:true whitespace-before:2 whitespace-after:2 lang:mysql decode:true\">ADVISE SELECT *\r\n       FROM info\r\n       WHERE ANY v IN OBJECT_PAIRS(translations)\r\n                 SATISFIES [LOWER(v.name),LOWER(v.val)] = [\"en\", \"Hello\"]\r\n       END\r\n\r\n\r\n{\r\n      \"index_statement\": \"CREATE INDEX adv_DISTINCT_object_pairs_translations_lower_name_lower_val ON `info`(DISTINCT ARRAY [lower((`v`.`name`)), lower((`v`.`val`))] FOR v in object_pairs((`translations`)) END)\",\r\n      \"keyspace_alias\": \"info\",\r\n      \"recommending_rule\": \"As chaves de \u00edndice seguem a ordem dos tipos de predicado: 2. equality\/null\/missing.\"\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong>Mais fun\u00e7\u00f5es de objeto<\/strong><\/h4>\n<p>O N1QL tem mais <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/objectfun.html\">objeto<\/a> e fun\u00e7\u00f5es de dados aninhadas para ajudar com modelos de dados complexos.  Confira o conjunto completo de fun\u00e7\u00f5es de objeto e a se\u00e7\u00e3o <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/tokenfun.html\">fun\u00e7\u00f5es de token<\/a>.<\/p>\n<p><b>Refer\u00eancias:<\/b><\/p>\n<ol>\n<li>Fun\u00e7\u00f5es de objeto do Couchbae N1QL <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/objectfun.html\">Documenta\u00e7\u00e3o<\/a><\/li>\n<li>Couchbase <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/indexing-arrays.html\">Indexa\u00e7\u00e3o de matrizes\u00a0<\/a><\/li>\n<li>Couchbase <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/create-right-index-get-right-performance\/\">blog de \u00edndice<\/a><\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"<p>Use N1QL when you&#8217;re in a JSON pickle. &#8212; Confucius For the JSON data model, the advice is to think of collections as tables, JSON document as denormalized rows and field names as columns &#8211; roughly. All this holds in [&hellip;]<\/p>","protected":false},"author":55,"featured_media":8408,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1815,2453,1812],"tags":[1447,1505,1261],"ppma_author":[8929],"class_list":["post-8407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-best-practices-and-tutorials","category-global-secondary-index","category-n1ql-query","tag-data-modeling","tag-index","tag-json"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.2 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flexible Query &amp; Indexing for Flexible JSON Model. - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/pt\/flexible-query-indexing-for-flexible-json-model\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flexible Query &amp; Indexing for Flexible JSON Model.\" \/>\n<meta property=\"og:description\" content=\"Use N1QL when you&#8217;re in a JSON pickle. &#8212; Confucius For the JSON data model, the advice is to think of collections as tables, JSON document as denormalized rows and field names as columns &#8211; roughly. All this holds in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/flexible-query-indexing-for-flexible-json-model\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-13T07:33:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T00:21:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1130\" \/>\n\t<meta property=\"og:image:height\" content=\"755\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Keshav Murthy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rkeshavmurthy\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Keshav Murthy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/\"},\"author\":{\"name\":\"Keshav Murthy\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636\"},\"headline\":\"Flexible Query &amp; Indexing for Flexible JSON Model.\",\"datePublished\":\"2020-04-13T07:33:48+00:00\",\"dateModified\":\"2025-06-14T00:21:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/\"},\"wordCount\":714,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg\",\"keywords\":[\"Data Modeling\",\"Index\",\"JSON\"],\"articleSection\":[\"Application Design\",\"Best Practices and Tutorials\",\"Global Secondary Index\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/\",\"name\":\"Flexible Query &amp; Indexing for Flexible JSON Model. - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg\",\"datePublished\":\"2020-04-13T07:33:48+00:00\",\"dateModified\":\"2025-06-14T00:21:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg\",\"width\":1130,\"height\":755},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flexible Query &amp; Indexing for Flexible JSON Model.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636\",\"name\":\"Keshav Murthy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4e51d72fc07c662aa791316deafffac4\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g\",\"caption\":\"Keshav Murthy\"},\"description\":\"Keshav Murthy is a Vice President at Couchbase R&amp;D. Previously, he was at MapR, IBM, Informix, Sybase, with more than 20 years of experience in database design &amp; development. He lead the SQL and NoSQL R&amp;D team at IBM Informix. He has received two President's Club awards at Couchbase, two Outstanding Technical Achievement Awards at IBM. Keshav has a bachelor's degree in Computer Science and Engineering from the University of Mysore, India, holds eleven US patents and has four US patents pending.\",\"sameAs\":[\"https:\/\/blog.planetnosql.com\/\",\"https:\/\/x.com\/rkeshavmurthy\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/pt\/author\/keshav-murthy\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Flexible Query &amp; Indexing for Flexible JSON Model. - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/pt\/flexible-query-indexing-for-flexible-json-model\/","og_locale":"pt_BR","og_type":"article","og_title":"Flexible Query &amp; Indexing for Flexible JSON Model.","og_description":"Use N1QL when you&#8217;re in a JSON pickle. &#8212; Confucius For the JSON data model, the advice is to think of collections as tables, JSON document as denormalized rows and field names as columns &#8211; roughly. All this holds in [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/flexible-query-indexing-for-flexible-json-model\/","og_site_name":"The Couchbase Blog","article_published_time":"2020-04-13T07:33:48+00:00","article_modified_time":"2025-06-14T00:21:46+00:00","og_image":[{"width":1130,"height":755,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg","type":"image\/jpeg"}],"author":"Keshav Murthy","twitter_card":"summary_large_image","twitter_creator":"@rkeshavmurthy","twitter_misc":{"Written by":"Keshav Murthy","Est. reading time":"5 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/"},"author":{"name":"Keshav Murthy","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636"},"headline":"Flexible Query &amp; Indexing for Flexible JSON Model.","datePublished":"2020-04-13T07:33:48+00:00","dateModified":"2025-06-14T00:21:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/"},"wordCount":714,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg","keywords":["Data Modeling","Index","JSON"],"articleSection":["Application Design","Best Practices and Tutorials","Global Secondary Index","SQL++ \/ N1QL Query"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/","url":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/","name":"Flexible Query &amp; Indexing for Flexible JSON Model. - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg","datePublished":"2020-04-13T07:33:48+00:00","dateModified":"2025-06-14T00:21:46+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/04\/pencil.jpg","width":1130,"height":755},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/flexible-query-indexing-for-flexible-json-model\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Flexible Query &amp; Indexing for Flexible JSON Model."}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"Blog do Couchbase","description":"Couchbase, o banco de dados NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"Blog do Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636","name":"Keshav Murthy","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4e51d72fc07c662aa791316deafffac4","url":"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g","caption":"Keshav Murthy"},"description":"Keshav Murthy \u00e9 vice-presidente de P&amp;D da Couchbase. Anteriormente, ele trabalhou na MapR, IBM, Informix e Sybase, com mais de 20 anos de experi\u00eancia em design e desenvolvimento de bancos de dados. Ele liderou a equipe de P&amp;D de SQL e NoSQL na IBM Informix. Ele recebeu dois pr\u00eamios President's Club na Couchbase e dois Outstanding Technical Achievement Awards na IBM. Keshav \u00e9 bacharel em Ci\u00eancia da Computa\u00e7\u00e3o e Engenharia pela Universidade de Mysore, \u00cdndia, det\u00e9m onze patentes nos EUA e tem quatro patentes pendentes nos EUA.","sameAs":["https:\/\/blog.planetnosql.com\/","https:\/\/x.com\/rkeshavmurthy"],"url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/keshav-murthy\/"}]}},"authors":[{"term_id":8929,"user_id":55,"is_guest":0,"slug":"keshav-murthy","display_name":"Keshav Murthy","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g","author_category":"","last_name":"Murthy","first_name":"Keshav","job_title":"","user_url":"https:\/\/blog.planetnosql.com\/","description":"Keshav Murthy \u00e9 vice-presidente de P&amp;D da Couchbase. Anteriormente, ele trabalhou na MapR, IBM, Informix e Sybase, com mais de 20 anos de experi\u00eancia em design e desenvolvimento de bancos de dados. Ele liderou a equipe de P&amp;D de SQL e NoSQL na IBM Informix. Recebeu dois pr\u00eamios President's Club na Couchbase e dois Outstanding Technical Achievement Awards na IBM. Keshav \u00e9 bacharel em Ci\u00eancia da Computa\u00e7\u00e3o e Engenharia pela Universidade de Mysore, \u00cdndia, det\u00e9m dez patentes nos EUA e tem tr\u00eas patentes pendentes nos EUA."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/8407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=8407"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/8407\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/8408"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=8407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=8407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=8407"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=8407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}