Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
elasticsearch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
elasticsearch
Commits
4e15941f6ce1
Commit
4e15941f6ce1
authored
8 years ago
by
Arthur Lutz
Browse files
Options
Downloads
Patches
Plain Diff
[hooks] initial version of hook to index content when created or changed
parent
680de326f545
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hooks.py
+40
-0
40 additions, 0 deletions
hooks.py
with
40 additions
and
0 deletions
hooks.py
+
40
−
0
View file @
4e15941f
...
...
@@ -16,3 +16,43 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
cubicweb-elasticsearch specific hooks and operations
"""
import
logging
from
elasticsearch
import
Elasticsearch
from
elasticsearch.exceptions
import
ConnectionError
from
urllib3.exceptions
import
ProtocolError
from
cubicweb.server
import
hook
from
cubicweb.predicates
import
score_entity
from
cubes.elasticsearch.es
import
indexable_types
log
=
logging
.
getLogger
(
__name__
)
def
entity_indexable
(
entity
):
return
entity
.
cw_etype
in
indexable_types
(
entity
.
_cw
.
vreg
.
schema
)
class
ContentUpdateIndexES
(
hook
.
Hook
):
"""
detect content change and updates ES indexing
"""
__regid__
=
'
elasticsearch.contentupdatetoes
'
__select__
=
hook
.
Hook
.
__select__
&
score_entity
(
entity_indexable
)
events
=
(
'
after_update_entity
'
,
'
after_add_entity
'
)
category
=
'
es
'
def
__call__
(
self
):
locations
=
self
.
_cw
.
vreg
.
config
[
'
elasticsearch-locations
'
]
index_name
=
self
.
_cw
.
vreg
.
config
[
'
index-name
'
]
serializer
=
self
.
entity
.
cw_adapt_to
(
'
ISerializable
'
)
json
=
serializer
.
serialize
()
es
=
Elasticsearch
(
locations
and
locations
.
split
(
'
,
'
)
or
None
)
try
:
# TODO option pour coté async ?
es
.
index
(
index
=
index_name
,
doc_type
=
self
.
entity
.
cw_etype
,
body
=
json
)
except
(
ConnectionError
,
ProtocolError
):
log
.
debug
(
'
Failed to index in hook, could not connect to ES
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment