Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ChEMBL
C
ChEMBL
Main Web Interface
Elasticsearch Proxy API
Commits
c10a6f0c
Commit
c10a6f0c
authored
Oct 14, 2021
by
David Mendez
Browse files
ES Docs: allow to ptovide a custom id property
parent
10b2cd8a
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
5 deletions
+62
-5
app/blueprints/es_proxy/controllers/es_proxy_controller.py
app/blueprints/es_proxy/controllers/es_proxy_controller.py
+2
-1
app/blueprints/es_proxy/controllers/marshmallow_schemas.py
app/blueprints/es_proxy/controllers/marshmallow_schemas.py
+1
-0
app/blueprints/es_proxy/services/es_proxy_service.py
app/blueprints/es_proxy/services/es_proxy_service.py
+22
-2
app/es_data/es_data.py
app/es_data/es_data.py
+1
-1
app/swagger/swagger.yaml
app/swagger/swagger.yaml
+6
-0
functional_tests/run_functional_tests.py
functional_tests/run_functional_tests.py
+3
-1
functional_tests/specific_tests/fun_test_get_document_by_custom_id_prop.py
...specific_tests/fun_test_get_document_by_custom_id_prop.py
+27
-0
No files found.
app/blueprints/es_proxy/controllers/es_proxy_controller.py
View file @
c10a6f0c
...
...
@@ -63,7 +63,8 @@ def get_es_doc(index_name, doc_id):
"""
try
:
source
=
request
.
args
.
get
(
'source'
)
json_response
=
es_proxy_service
.
get_es_doc
(
index_name
,
doc_id
,
source
)
custom_id_property
=
request
.
args
.
get
(
'custom_id_property'
)
json_response
=
es_proxy_service
.
get_es_doc
(
index_name
,
doc_id
,
source
,
custom_id_property
)
http_response
=
jsonify
(
json_response
)
http_cache_utils
.
add_cache_headers_to_response
(
http_response
)
return
http_response
...
...
app/blueprints/es_proxy/controllers/marshmallow_schemas.py
View file @
c10a6f0c
...
...
@@ -23,3 +23,4 @@ class ESProxyDoc(CommonSchema):
index_name
=
fields
.
String
(
required
=
True
)
doc_id
=
fields
.
String
(
required
=
True
)
source
=
fields
.
String
()
custom_id_property
=
fields
.
String
()
app/blueprints/es_proxy/services/es_proxy_service.py
View file @
c10a6f0c
...
...
@@ -62,16 +62,36 @@ def get_es_data(index_name, raw_es_query, raw_context, raw_contextual_sort_data,
return
response
def
get_es_doc
(
index_name
,
doc_id
,
source
=
None
):
def
get_es_doc
(
index_name
,
doc_id
,
source
=
None
,
custom_id_property
=
None
):
"""
:param index_name: name of the index to which the doc belongs
:param doc_id: id of the document to search for
:param source: list of properties to get
:param custom_id_property: custom id property to use instead of _id
:return: the json response from elasticsearch of the document
"""
try
:
response
=
es_data
.
get_es_doc
(
index_name
,
doc_id
,
source
)
item_id
=
doc_id
use_custom_id_property
=
custom_id_property
is
not
None
if
use_custom_id_property
:
es_query
=
{
"_source"
:
source
,
"query"
:
{
"terms"
:
{
custom_id_property
:
[
doc_id
]
}
}
}
search_response
=
es_data
.
get_es_response
(
index_name
,
es_query
)
hits
=
search_response
.
get
(
'hits'
,
{}).
get
(
'hits'
,[])
if
len
(
hits
)
==
0
:
raise
ESDataNotFoundError
(
f
'No item found in index
{
index_name
}
with
{
custom_id_property
}
==
{
doc_id
}
'
)
item_id
=
hits
[
0
][
'_id'
]
response
=
es_data
.
get_es_doc
(
index_name
,
item_id
,
source
)
return
response
except
es_data
.
ESDataNotFoundError
as
error
:
raise
ESDataNotFoundError
(
str
(
error
))
...
...
app/es_data/es_data.py
View file @
c10a6f0c
...
...
@@ -113,7 +113,7 @@ def get_es_doc(index_name, doc_id, source=None):
"""
properties_list
=
[]
if
source
is
None
else
source
.
split
(
','
)
using_source
=
source
is
not
None
cache_key
=
f
'document-
{
index_name
}
-
{
doc_id
}
-
{
","
.
join
(
properties_list
)
}
-
{
RUN_CONFIG
.
get
(
"cache_key_suffix"
)
}
'
cache_key
=
f
'document-
{
index_name
}
-
{
doc_id
}
-
source:
{
","
.
join
(
properties_list
)
}
-
{
RUN_CONFIG
.
get
(
"cache_key_suffix"
)
}
'
app_logging
.
debug
(
f
'cache_key:
{
cache_key
}
'
)
equivalent_query
=
{
...
...
app/swagger/swagger.yaml
View file @
c10a6f0c
...
...
@@ -99,6 +99,12 @@ paths:
required
:
false
type
:
'
string'
default
:
'
molecule_chembl_id,pref_name'
-
name
:
"
custom_id_property"
in
:
"
query"
description
:
"
By
default
the
doc_id
will
match
with
the
_id
field,
but
you
can
pass
another
field
here
if
you
prefer"
type
:
'
string'
default
:
'
target_chembl_id'
responses
:
'
200'
:
description
:
"
success"
...
...
functional_tests/run_functional_tests.py
View file @
c10a6f0c
...
...
@@ -7,7 +7,8 @@ import argparse
from
specific_tests
import
fun_test_simple_query
,
fun_test_query_with_context
,
\
fun_test_query_with_search_by_ids_context
,
fun_test_property_config
,
\
fun_test_group_config
,
fun_test_facets_group_config
,
fun_test_get_document
,
fun_test_id_properties
,
\
fun_test_group_config
,
fun_test_facets_group_config
,
fun_test_get_document
,
fun_test_get_document_by_custom_id_prop
,
\
fun_test_id_properties
,
\
fun_test_get_context_data
,
fun_test_search_parsing
,
fun_test_url_shortening
,
fun_test_element_usage
,
\
fun_test_go_slim_target_classification
,
fun_test_in_vivo_assay_classification
,
\
fun_test_organism_taxonomy_target_classification
,
fun_test_protein_target_classification
,
\
...
...
@@ -34,6 +35,7 @@ def run():
for
test_module
in
[
fun_test_simple_query
,
fun_test_query_with_context
,
fun_test_query_with_search_by_ids_context
,
fun_test_property_config
,
fun_test_group_config
,
fun_test_facets_group_config
,
fun_test_get_document
,
fun_test_get_document_by_custom_id_prop
fun_test_id_properties
,
fun_test_get_context_data
,
fun_test_search_parsing
,
fun_test_url_shortening
,
fun_test_element_usage
,
...
...
functional_tests/specific_tests/fun_test_get_document_by_custom_id_prop.py
0 → 100644
View file @
c10a6f0c
# pylint: disable=import-error,unused-argument
"""
Module that tests a group config
"""
from
specific_tests
import
utils
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
"""
Tests getting the configuration of a group
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
print
(
'-------------------------------------------'
)
print
(
'Testing getting a document by id'
)
print
(
'-------------------------------------------'
)
url
=
f
'
{
server_base_url
}
/es_data/get_es_document/chembl_eubopen_target/CHEMBL4524126'
utils
.
assert_get_request_succeeds
(
url
)
params
=
{
'source'
:
'pref_name'
,
'custom_id_property'
:
'target_chembl_id'
}
utils
.
assert_get_request_succeeds
(
url
,
params
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment