FT.PROFILE

Introduction and Use Case(s)

FT.PROFILE is a command in Redis used with the RedisSearch module to allow detailed profiling of queries. This command helps in understanding the performance characteristics and execution details of full-text search queries, making it useful for optimizing query performance and debugging complex searches.

Syntax

  1. FT.PROFILE {index} {QUERY|SEARCH} [query_args]

Parameter Explanations

  • index: The name of the index you are querying.
  • QUERY|SEARCH: Determines whether you are running a free-text query (QUERY) or a SEARCH.
  • query_args: Additional arguments that specify the search terms and options for the query.

Return Values

The command returns a detailed report on the execution of the query, including various stages and steps taken by the query engine. This includes parsing time, execution time for different parts of the query, and how results were filtered and returned.

Example Output

  1. 1) "Parsing"
  2. 2) (execution details)
  3. 3) "Pipeline"
  4. 4) (stage details)
  5. 5) "Total Execution Time"
  6. 6) (time in milliseconds)

Code Examples

  1. dragonfly> FT.CREATE myIdx SCHEMA title TEXT WEIGHT 5.0 body TEXT
  2. OK
  3. dragonfly> FT.PROFILE myIdx SEARCH QUERY "hello world"
  4. 1) "Parsing"
  5. 2) "Execution time: 0.123 ms"
  6. 3) "Pipeline"
  7. 4) "Stage 1: Term matching"
  8. 5) "Matched documents: 10"
  9. 6) "Total Execution Time"
  10. 7) "Execution time: 1.456 ms"

Best Practices

  • Use FT.PROFILE in development or staging environments to fine-tune query performance before deploying to production.
  • Compare profiling reports over time to identify any regressions in query performance.

Common Mistakes

  • Using FT.PROFILE in a high-traffic production environment can impact performance due to its detailed logging nature.
  • Not fully understanding the output can lead to misinterpretation. It’s beneficial to familiarize yourself with the typical stages and times involved in your specific queries.

FAQs

What is the difference between QUERY and SEARCH in FT.PROFILE?

QUERY allows for more complex free-text searches, while SEARCH is typically used for structured searches within the index.

Can I use FT.PROFILE to profile aggregation queries?

Currently, FT.PROFILE is designed for profiling QUERY and SEARCH commands. Profiling for aggregation might require different approaches or tools.