elasticsearch7 python search() api 使用 HTTP POST 方法而不是 HTTP GET

问题描述

我有一个带有映射的弹性搜索索引“job-index”

{
    "mappings": {
        "properties": {
            "join_field": {
                "type": "join","relations": {
                    "job": "checkpoint"
                }
            }
        }
    }
}

当我执行

GET /job-index/_search

{
  "query": {
    "term": {
      "join_field.name": "job"
    }
  }
}

它返回工作类型的所有文档。

但是当我使用 HTTP POST 执行相同的查询时,它返回 0 个命中。

我使用的是 elasticsearch7 python,它使用 HTTP POST 作为搜索 API。下面是我使用的python代码

from elasticsearch7 import Elasticsearch
es7 = Elasticsearch('localhost:9200')
resp = es7.search(body=json.dumps(payload),index=self.job_index)

下面是日志

DEBUG:urllib3.connectionpool:http://localhost:9200 "POST /job-index/_search HTTP/1.1" 200 160
INFO:elasticsearch:POST http://localhost:9200/job-index/_search [status:200 request:0.006s]
DEBUG:elasticsearch:> {"query": {"term": {"join_field.name": "job"}}}
DEBUG:elasticsearch:< {"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"Failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)