如何记录或打印被调用的python elasticsearch-dsl查询 [英] how to log or print python elasticsearch-dsl query that gets invoked

查看:1325
本文介绍了如何记录或打印被调用的python elasticsearch-dsl查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 elasticsearch-dsl 将我的python应用程序查询弹性搜索。 / p>

要调试由elasticsearch-dsl库生成的查询,我无法记录或打印弹性搜索的最终查询。



例如,像这样查看请求正文发送到弹性搜索:

  {
query:{
query_string:{
query:Dav *,
fields:[name,short_code],
analyze_wildcard:true
}
}
}

试图将弹性搜索日志级别提升到TRACE。即使如此,无法看到执行的查询。

解决方案

看看我的博客文章这里索引级别的Slowlog设置部分。基本上,您可以使用slowlog在单独的日志文件中打印Elasticsearch生成查询。我建议使用非常低的阈值来查看所有查询。



例如,对于特定索引,

  PUT / test_index / _settings 
{
index:{
slowlog.level:trace,
search.slowlog.threshold.query.trace:1ms
}
}
/ pre>

  PUT / _settings 
{
index:{
search.slowlog.level:trace,
search.slowlog.threshold.query.trace:1ms
}
}

作为所有索引的集群范围设置。



查询将被记录在您的 / logs 位置,一个名为 [CLUSTER_NAME] _index_search_slowlog.log的文件


I am using elasticsearch-dsl for my python application to query elastic search.

To debug what query is actually getting generated by elasticsearch-dsl library, I am unable to log or print the final query that goes to elasticsearch.

For example, like to see the request body sent to elasticsearch like this :

{
    "query": {
        "query_string": {
           "query": "Dav*",
           "fields": ["name", "short_code"],
           "analyze_wildcard": true
        }
    }
}

Tried to bring the elasticsearch log level to TRACE. Even then, unable to see the queries that got executed.

解决方案

Take a look at my blog post here, "Slowlog settings at index level" section. Basically, you can use slowlog to print in a separate log file Elasticsearch generates, the queries. I suggest using a very low threshold to be able to see all the queries.

For example, something like this, for a specific index:

PUT /test_index/_settings
{
  "index": {
    "search.slowlog.level": "trace",
    "search.slowlog.threshold.query.trace": "1ms"
  }
}

Or

PUT /_settings
{
  "index": {
    "search.slowlog.level": "trace",
    "search.slowlog.threshold.query.trace": "1ms"
  }
}

as a cluster-wide setting, for all the indices.

And the queries will be logged in your /logs location, a file called [CLUSTER_NAME]_index_search_slowlog.log.

这篇关于如何记录或打印被调用的python elasticsearch-dsl查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆