要不要再翻翻文档呢?

为什么es只能通过拼接url发起get请求查询,通过dsl查询就查不到东西

Elasticsearch | 作者 suoiruc | 发布于2020年12月21日 | 阅读数:2408

es版本6.3.0+ik6.3.0+拼音、6.3.0
 
·使用拼接url的方法,可以完成查询(另有问题:如果在companyname:后边不加一个_占位,似乎就也会有问题):
@staticmethod
def search(indexName, searchPayload):
url = "localhost:9200/" + str(indexName) + '/_search?' + "q=companyname:_ " + searchPayload
# 查询模式
payload={}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=json.dumps(payload))
print("do search func: \n", json.loads(response.text))
indexName = 'postgis_test'
ElasticsearchController.search(indexName, searchPayload='albb')

{'took': 55, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': 713023, 'max_score': 13.5527525, 'hits': [{'_index': 'postgis_test', '_type': 'doc', '_id': '3980', '_score': 13.5527525, '_source': {'DZZYMC_PINYIN': '爱宝兰设计公司', 'type': 'postgis_test', 'DZZYID': 3980}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '318573', '_score': 13.317461, '_source': {'DZZYMC_PINYIN': '博思艾伦咨询公司', 'type': 'postgis_test', 'DZZYID': 318573}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '1616696', '_score': 13.089866, '_source': {'DZZYMC_PINYIN': '湖南艾布鲁环保公司', 'type': 'postgis_test', 'DZZYID': 1616696}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '2943', '_score': 13.089866, '_source': {'DZZYMC_PINYIN': '艾力彼管理咨询公司', 'type': 'postgis_test', 'DZZYID': 2943}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '5140', '_score': 13.084759, '_source': {'DZZYMC_PINYIN': '爱丽堡酒店管理公司', 'type': 'postgis_test', 'DZZYID': 5140}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '1101', '_score': 12.970395, '_source': {'DZZYMC_PINYIN': '阿里巴巴供应链管理公司', 'type': 'postgis_test', 'DZZYID': 1101}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '93360', '_score': 12.869918, '_source': {'DZZYMC_PINYIN': '奥伯龙设计与制作公司', 'type': 'postgis_test', 'DZZYID': 93360}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '75254', '_score': 12.869918, '_source': {'DZZYMC_PINYIN': '安徽中安商业保理公司', 'type': 'postgis_test', 'DZZYID': 75254}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '303761', '_score': 12.868919, '_source': {'DZZYMC_PINYIN': '北仑安邸国际装修公司', 'type': 'postgis_test', 'DZZYID': 303761}}, {'_index': 'postgis_test', '_type': 'doc', '_id': '2499957', '_score': 12.675108, '_source': {'DZZYMC_PINYIN': '青岛百澳兰博工贸有限公司', 'type': 'postgis_test', 'DZZYID': 2499957}}]}}

·如下,使用dsl查询方法,查不到东西
@staticmethod
def searchByDSL(indexName, searchPayload): # query dsl查询
url = url = "localhost:9200/" + str(indexName) + '/_search'
payload={
"query": {
"match": {
"companyname": searchPayload
}
}
}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) #
print("do searchByDSL func: \n", json.loads(response.text))
indexName = 'postgis_test'
ElasticsearchController.searchByDSL(indexName=indexName, searchPayload='albb')

do searchByDSL func:
{'took': 2, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': 0, 'max_score': None, 'hits': []}}

 

 
已邀请:

要回复问题请先登录注册