1

我正在尝试使用 python 客户端进行弹性搜索,以使用 SQL 访问来查询索引以进行弹性搜索。我想使用 sql 语法查询索引。我如何向 elasticsearch 指定它必须读取 SQLsyntax?

 def searchText(text):
    t1 = time.time()
    es=Elasticsearch([{'host':'localhost','port':9200}])
    res =  es.search(index='global_res_todos_acco', size=10000, request_timeout=60,
                     body={'query':{
                                        "select * from global_res_todos_acco limit 100 where EntityList = " + text
                                    }
                          }
                     )
    GHList = []
    for hit in res['hits']['hits']:
            GHList.append(hit['_source']['Geohash7'])
    return(GHList)

我在控制台中收到以下错误

TypeError:无法序列化 {'select * from global_res_todos_acco where EntityList = phuket indian food'}

4

1 回答 1

3

如果您使用的是 Python 客户端,则需要使用该es.sql.query()函数:

es=Elasticsearch([{'host':'localhost','port':9200}])
es.sql.query(body={'query': 'select * from global_res_todos_acco...'})
于 2021-01-07T15:12:06.343 回答