分页
def search(q, from_, size=10):
return client.index(indexName).search(
q, opt_params={'limit': size,
'offset': from_,
}
)
向索引添加或修改内容
def addIndex(index, json, key):
return client.index(index).add_documents_json(json, primary_key=key)
删除索引
def deleteIndex(index):
try:
client.delete_index(index)
except:
pass
添加或修改停用词
def addStopWord():
print('添加或修改停用词')
wordList = [k.strip() for k in open('stop_words', encoding='utf-8').readlines() if k.strip() != '']
client.index(indexName).update_settings({
'stopWords': wordList,
})
print(client.index(indexName).get_settings())
设置排名规则
注意:一定要添加存在的属性
print(client.index(indexName).update_ranking_rules([
"id:desc",
"sort",
"words",
"typo",
"proximity",
"attribute",
"exactness"
]))
查询中排序
print(client.index(indexName).search('key', {
}))
查询任务执行情况
client.get_task(14483)
|