One of the ways to improve your application performance in Couchbase is to create indexes for common queries. However, when you are working with Spring Data using its standard DSL, the generated query is not very clear, which makes a little bit more difficult to create the right index to it.

This problem can be easily solved by enabling DEBUG log level in the class AbstractN1qlBasedQuery, it will print the generated N1QL query in the log, a behavior very similar to enabling the attribute show_sql in Hibernate.  Here is how you can set this configuration in your application.yml

You can also enable it via retorno de registro  by simply adding it as a dependency:

And then, add the logback.xml configuration file in your resources folder:

When you run your application again, the generated N1QL queries will be printed in the logs.

 

If you have any questions, ping me at @deniswsrosa

 

 

Autor

Postado por Denis Rosa, defensor dos desenvolvedores, Couchbase

Denis Rosa é um Developer Advocate do Couchbase e mora em Munique, na Alemanha. Ele tem uma sólida experiência como engenheiro de software e fala fluentemente Java, Python, Scala e Javascript. Denis gosta de escrever sobre pesquisa, Big Data, IA, microsserviços e tudo o mais que possa ajudar os desenvolvedores a criar um aplicativo bonito, mais rápido, estável e escalável.

6 Comentários

  1. Does this work with SpringBoot 2.4 with springdata-couchbase 4.1.1?I couldn’t enable logging for repository queries with below logback-spring.xml?

    %d{HH:mm:ss} [%thread] %-5level %logger{36} – %msg%n

    1. %d{HH:mm:ss} [%thread] %-5level %logger{36} – %msg%n

      1. Seems comment can neither be edited nor deleted.logback xml is distorted.But its the same as your example

    2. Denis Rosa, defensor dos desenvolvedores, Couchbase janeiro 13, 2021 em 11:34 am

      Hi! please use the package org.springframework.data.couchbase.core.query from Spring Data 4 onwards

Deixar uma resposta