T53161 elasticsearch can index nodes now. cli command. NOTE config changes!!

This commit is contained in:
2017-11-10 16:05:12 +01:00
parent 43fa8f1a45
commit d2a8f2a47f
13 changed files with 303 additions and 19 deletions

View File

@@ -26,15 +26,16 @@ autocomplete = es.analyzer(
class User(es.DocType):
"""
Elastic document describing user
"""
"""Elastic document describing user."""
name = es.String(
fielddata=True,
analyzer=autocomplete,
)
class Meta:
index = 'users'
class Node(es.DocType):
"""
@@ -43,12 +44,39 @@ class Node(es.DocType):
node_type = es.Keyword()
x_code = es.String(
multi=True,
objectID = es.Keyword()
name = es.String(
fielddata=True,
analyzer=autocomplete,
analyzer=autocomplete
)
user_id = es.Keyword()
user_name = es.String(
fielddata=True,
analyzer=autocomplete
)
description = es.String()
is_free = es.Boolean()
project_id = es.Keyword()
project_name = es.String()
media = es.Keyword()
picture_url = es.Keyword()
tags = es.Keyword(multi=True)
license_notes = es.String()
created_at = es.Date()
updated_at = es.Date()
class Meta:
index = 'nodes'
def create_doc_from_user_data(user_to_index):
doc_id = user_to_index['objectID']
@@ -59,8 +87,25 @@ def create_doc_from_user_data(user_to_index):
def create_doc_from_node_data(node_to_index):
# node stuff
doc_id = node_to_index['objectID']
doc_id = str(node_to_index['objectID'])
doc = Node(_id=doc_id)
doc.node_type = node_to_index['node_type']
doc.name = node_to_index['name']
doc.user_id = str(node_to_index['user']['_id'])
doc.user_name = node_to_index['user']['full_name']
doc.project_id = str(node_to_index['project']['_id'])
doc.project_name = node_to_index['project']['name']
if node_to_index['node_type'] == 'asset':
doc.media = node_to_index['media']
doc.picture_url = node_to_index.get('picture')
doc.tags = node_to_index.get('tags')
doc.license_notes = node_to_index.get('license_notes')
doc.created_at = node_to_index['created']
doc.updated_at = node_to_index['updated']
return doc