How to find which Index is being used?

HI,

I am using the java spring sdk to connect to couchbase server(enterprise).
How do i find out which index is being used when i get data from my application?

Thanks
Prince

If you know the statements issued you could simply EXPLAIN them to see the access plans and thus indices used.

Depending on your application and overall server activity you may be able to use the Indexer REST API to identify the most commonly used indices:
https://docs.couchbase.com/server/current/rest-api/rest-index-stats.html

("last_known_scan_time" & "num_requests" likely to be the indicators. You can convert "last_known_scan_time" to a timestamp with: SELECT millis_to_str(<value>/1000000); )

Alternatively, you may also be able to monitor completed requests (you can configure this to capture by IP or by user for example) for the statements issued and select the access plans with:

SELECT *,meta().plan FROM system:completed_requests

If your application is using prepared statements, system:prepareds will hold access plans for them which can be accessed with:

SELECT *,meta().plan FROM system:prepareds

Ref: https://docs.couchbase.com/server/current/manage/monitor/monitoring-n1ql-query.html

HTH.

spring-data-couchbase will log the n1ql statements with this logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d %5p %40.40c:%4L - %m%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="console"/>
    </root>
    <logger name="org.springframework.data.couchbase.core" level="debug"/>"
</configuration>

you will also need a logger implementation. I think this will suffice:

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.3</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.19.0</version>
            <optional>true</optional>
        </dependency>