python调用elasticsearch_dsl的indices.analyze接口分析字符串遇到的坑

今天尝试用 elasticsearch_dsl 的 indices.analyze 接口分析字符串遇到的大坑,我所用的版本是 elasticsearch-dsl 6.4.0
我看的视频教程中调用 indices.analyze 接口是这样写的:
res = es.indices.analyze(index=index,body=text,analyzer='ik_max_word',params={'filter':["lowercase"]} )
调试运行却发现提示这个错误:
TypeError: analyze() got an unexpected keyword argument 'analyzer'
查看源码发现我所用的这个版本里面已经没有 analyzer 这个参数了

    def analyze(self, index=None, body=None, params=None):
        """
        Perform the analysis process on a text and return the tokens breakdown of the text.
        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html>`_

        :arg index: The name of the index to scope the operation
        :arg body: Define analyzer/tokenizer parameters and the text on which
            the analysis should be performed
        :arg format: Format of the output, default 'detailed', valid choices
            are: 'detailed', 'text'
        :arg prefer_local: With `true`, specify that a local shard should be
            used if available, with `false`, use a random shard (default: true)
        """
        return self.transport.perform_request(
            "GET", _make_path(index, "_analyze"), params=params, body=body
        )

试着将分析字典写在 body 参数中:
res = es.indices.analyze(index=index,body={'text':text,'analyzer':"ik_max_word"}, params={'filter':["lowercase"]})
但是还是不行,提示了我这个错误:
elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', 'request [/cnblog/_analyze] contains unrecognized parameter: [filter] -> did you mean [filter_path]?')
经过各种尝试,后来试着把 filter 字段也写在 body参数中,终于测试成功了
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值