我正在尝试在项目中实现elasticsearch,但是在尝试运行此命令python manage.py index_orders
我尝试将elasticsearch版本更改为最新版本(7.1.1)并运行它。
这是我要运行的命令类
index_orders.py
class Command(BaseCommand):
help = 'Indexes Orders in Elastic Search'
def handle(self, *args, **options):
es = Elasticsearch(
[{'host': settings.ES_HOST, 'port': settings.ES_PORT}],
index="order"
)
order_index = Index('order')
order_index.doc_type(OrderDoc)
if order_index.exists():
order_index.delete()
print('Deleted order index.')
OrderDoc.init()
result = bulk(
client=es,
actions=(order.indexing() for order in Order.objects.all().iterator())
)
print('Indexed orders.')
print(result)
这是错误消息
Traceback (most recent call last):
File "manage.py", line 30, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/app/blowhorn/order/management/commands/index_orders.py", line 26, in handle
OrderDoc.init()
File "/usr/local/lib/python3.6/site-packages/elasticsearch_dsl/document.py", line 138, in init
i.save(using=using)
File "/usr/local/lib/python3.6/site-packages/elasticsearch_dsl/index.py", line 289, in save
current_settings = self.get_settings(using=using)[self._name]['settings']['index']
KeyError: '*'