Python 在Django Restframework中使用elasticsearch的最佳方式是什么
我很困惑如何在django restframework中使用elasticsearch。Python 在Django Restframework中使用elasticsearch的最佳方式是什么,python,django,elasticsearch,django-rest-framework,Python,Django,elasticsearch,Django Rest Framework,我很困惑如何在django restframework中使用elasticsearch。 请帮帮我 在刺痛我的头并在网络上进行研究之后,我创建了这个非常简单的解决方案 from elasticsearch import Elasticsearch, RequestsHttpConnection import datetime import socket from requests_aws4auth import AWS4Auth class EsHelper(): conn = ""
请帮帮我 在刺痛我的头并在网络上进行研究之后,我创建了这个非常简单的解决方案
from elasticsearch import Elasticsearch, RequestsHttpConnection
import datetime
import socket
from requests_aws4auth import AWS4Auth
class EsHelper():
conn = ""
index = "index"
HOSTNAME = socket.gethostname()
def __init__(self):
self.conn = Elasticsearch(['localhost:9200'])
exist = self.conn.indices.exists(self.index)
if not(exist):
self.conn.indices.create('index', body={
'settings': {
'analysis': {
'filter': {
'autocomplete_filter': {
'type': 'edge_ngram',
'min_gram': 1,
'max_gram': 20
}
},
'analyzer': {
'autocomplete': {
'type': 'custom',
'tokenizer': 'standard',
'filter': [
'lowercase',
'autocomplete_filter'
]
}
}
},
'index': {
'number_of_shards': '5',
'number_of_replicas': '1'
}
},
})
def EsAddIndex(self, index, type, id, body):
self.conn.index(index=index, doc_type=type, id=id, body=body)
def EsUpdateIndex(self, index, type, id, body):
self.conn.update(index=index, doc_type=type, id=id, body=body)
def EsSearch(self, index, page, size, searchTerm):
body = {
'query': {
'match': searchTerm
},
'sort': {
'created': {
'order': 'desc'
}
},
'filter': {
'term': {
'super_verification': 'verified'
}
}
}
res = self.conn.search(index=index, body=body)
output = []
for doc in res['hits']['hits']:
output.append(doc['_source'])
return output
展示你到目前为止所做的事情,也许有人可以帮助你!我只是想知道如何将elasticsearch与django集成。没有,我从哪里得到了关于这个的正确文档对不起,但是谷歌的第一个请求给了我关于如何使用Elasticsearch与Django的教程的链接。我已经看到了这些链接,但它没有达到标准。你能在这里分享这些链接吗