问题描述
我正在尝试使用 python 客户端进行弹性搜索,以使用 sql 访问进行弹性搜索来查询索引。我想使用 sql 语法查询索引。我如何向elasticsearch 指定它必须读取sql 语法?
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'}
解决方法
如果您使用的是 Python 客户端,则需要使用 es.sql.query()
函数:
es=Elasticsearch([{'host':'localhost','port':9200}])
es.sql.query(body={'query': 'select * from global_res_todos_acco...'})