How to find which Index is being used?


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?


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:

("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



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

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

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