Commit 10b06c29 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Forward ES errors to client in esmaterials endpoint. Better doc for esmaterials.

parent b4014438
......@@ -294,9 +294,12 @@ def get_es_materials(page, per_page):
}
# checking the validity of the syntax of the elastic search POSTed query
is_query_valid = es.indices.validate_query(index=es_config['index'], doc_type='search', body=dict(query=json_data))
is_query_valid = es.indices.validate_query(index=es_config['index'], doc_type='search', body=dict(query=json_data), explain=True)
if is_query_valid['valid'] is False:
raise InvalidEncRequest("Query syntax is not valid.", 400)
if 'error' in is_query_valid:
raise InvalidEncRequest("Query syntax is not valid.", 400, more=dict(reason=is_query_valid['error']))
else:
raise InvalidEncRequest("Query syntax is not valid.", 400)
# if the POSTed query syntax is valid we perform the query
es_search_results = es.search(index=es_config['index'], doc_type='material', body=query)
......
......@@ -15,11 +15,16 @@
class InvalidEncRequest(Exception):
def __init__(self, message, status_code):
def __init__(self, message, status_code, more=None):
super().__init__(message)
self._message = message
self._more = more
self.status_code = status_code
def to_dict(self):
return dict(status=self.status_code, error=self._message)
the_dict = dict(status=self.status_code, error=self._message)
if self._more is not None:
for key, value in self._more.items():
the_dict[key] = value
return the_dict
......@@ -667,72 +667,32 @@ In fact, the `/materials` endpoints returns the internally used Elastic Search q
the key `es_query`. This can be a great resource of examples to get started with the Elastic Search endpoint of this API.
Using the Elastic Search index requires some insights into the index itself and the stored data to use it effectively.
The Elastic Search index contains the following mappings and respectively only these keys can be used in your queries:
The Elastic Search index contains the following properties and respectively only these properties can be used in your queries:
```
{
"mappings":{
"material":{
"properties":{
"atom_labels":{
"type":"text",
"analyzer":"formula_analyzer"
},
"atom_labels_keyword":{
"type":"keyword"
},
"basis_set_type":{
"type":"keyword"
},
"calculations":{
"type":"long"
},
"code_name":{
"type":"keyword"
},
"crystal_system":{
"type":"keyword"
},
"formula":{
"type":"keyword"
},
"formula_reduced":{
"type":"keyword"
},
"functional_type":{
"type":"keyword"
},
"mass_density":{
"type":"float"
},
"material_hash":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"material_id":{
"type":"long"
},
"material_name":{
"type":"keyword"
},
"space_group_number":{
"type":"keyword"
},
"structure_type":{
"type":"keyword"
},
"system_type":{
"type":"keyword"
}
}
}
}
}
material_id : int # the encyclopedia id of the material
material_hash : keyword # unique hash that ids the material through the NOMAD infrastrcuture
material_name : keyword
formula : keyword
formula_reduced : keyword
atom_labels : text # the formula tokenized element by element
atom_labels_keyword : keyword # all elements concatenated
system_type : keyword
crystal_system : keyword
structure_type : keyword
space_group_number : int
code_name : array[keyword]
basis_set_type : array[keyword]
functional_type : array[keyword]
group_type : array[keyword]
has_band_structure : bool
band_gap : array[float] # length 2, [min, max]
band_gap_direct : array[keyword]
has_dos : bool
has_fermi_surface : bool
has_thermal_properties : bool
mass_density : array[float] # length 2, [min, max]
calculations : int # number of calculations for this material
```
Refer to the Elastic Search [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) for details on mappings. The `atom_labels` text analyzer tokenizes the
......
......@@ -537,70 +537,30 @@ Server: nginx/<span class="hljs-number">1.10</span><span class="hljs-number">.1<
<p>In fact, the <code>/materials</code> endpoints returns the internally used Elastic Search query as part of its response under
the key <code>es_query</code>. This can be a great resource of examples to get started with the Elastic Search endpoint of this API.</p>
<p>Using the Elastic Search index requires some insights into the index itself and the stored data to use it effectively.
The Elastic Search index contains the following mappings and respectively only these keys can be used in your queries:</p>
<pre><code>{
"<span class="hljs-attribute">mappings</span>":<span class="hljs-value">{
"<span class="hljs-attribute">material</span>":<span class="hljs-value">{
"<span class="hljs-attribute">properties</span>":<span class="hljs-value">{
"<span class="hljs-attribute">atom_labels</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"text"</span></span>,
"<span class="hljs-attribute">analyzer</span>":<span class="hljs-value"><span class="hljs-string">"formula_analyzer"</span>
</span>}</span>,
"<span class="hljs-attribute">atom_labels_keyword</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">basis_set_type</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">calculations</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"long"</span>
</span>}</span>,
"<span class="hljs-attribute">code_name</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">crystal_system</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">formula</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">formula_reduced</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">functional_type</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">mass_density</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"float"</span>
</span>}</span>,
"<span class="hljs-attribute">material_hash</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"text"</span></span>,
"<span class="hljs-attribute">fields</span>":<span class="hljs-value">{
"<span class="hljs-attribute">keyword</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span></span>,
"<span class="hljs-attribute">ignore_above</span>":<span class="hljs-value"><span class="hljs-number">256</span>
</span>}
</span>}
</span>}</span>,
"<span class="hljs-attribute">material_id</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"long"</span>
</span>}</span>,
"<span class="hljs-attribute">material_name</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">space_group_number</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">structure_type</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}</span>,
"<span class="hljs-attribute">system_type</span>":<span class="hljs-value">{
"<span class="hljs-attribute">type</span>":<span class="hljs-value"><span class="hljs-string">"keyword"</span>
</span>}
</span>}
</span>}
</span>}
</span>}</code></pre>
The Elastic Search index contains the following properties and respectively only these properties can be used in your queries:</p>
<pre><code>material_id : <span class="hljs-type">int</span> <span class="hljs-comment"># the encyclopedia id of the material</span>
material_hash : keyword <span class="hljs-comment"># unique hash that ids the material through the NOMAD infrastrcuture</span>
material_name : keyword
formula : keyword
formula_reduced : keyword
atom_labels : text <span class="hljs-comment"># the formula tokenized element by element</span>
atom_labels_keyword : keyword <span class="hljs-comment"># all elements concatenated</span>
system_type : keyword
crystal_system : keyword
structure_type : keyword
space_group_number : <span class="hljs-type">int</span>
code_name : <span class="hljs-type">array</span>[keyword]
basis_set_type : <span class="hljs-type">array</span>[keyword]
functional_type : <span class="hljs-type">array</span>[keyword]
group_type : <span class="hljs-type">array</span>[keyword]
has_band_structure : <span class="hljs-type">bool</span>
band_gap : <span class="hljs-type">array</span>[<span class="hljs-type">float</span>] <span class="hljs-comment"># length 2, [min, max]</span>
band_gap_direct : <span class="hljs-type">array</span>[keyword]
has_dos : <span class="hljs-type">bool</span>
has_fermi_surface : <span class="hljs-type">bool</span>
has_thermal_properties : <span class="hljs-type">bool</span>
mass_density : <span class="hljs-type">array</span>[<span class="hljs-type">float</span>] <span class="hljs-comment"># length 2, [min, max]</span>
calculations : <span class="hljs-type">int</span> <span class="hljs-comment"># number of calculations for this material</span></code></pre>
<p>Refer to the Elastic Search <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html">documentation</a> for details on mappings. The <code>atom_labels</code> text analyzer tokenizes the
atom label String into individual atoms.</p>
<p>Here is an example of a material in the index.</p>
......@@ -1243,7 +1203,7 @@ Each collection (materials, calculations, …) will contain a similar block like
"<span class="hljs-attribute">error</span>": <span class="hljs-value"><span class="hljs-string">"not found"</span></span>,
"<span class="hljs-attribute">message</span>": <span class="hljs-value"><span class="hljs-string">"invalid resource URI"</span></span>,
"<span class="hljs-attribute">status</span>": <span class="hljs-value"><span class="hljs-number">404</span>
</span>}</code></pre><div style="height: 1px;"></div></div></div></div></div></section></div></div></div><p style="text-align: center;" class="text-muted">Generated by&nbsp;<a href="https://github.com/danielgtaylor/aglio" class="aglio">aglio</a>&nbsp;on 12 Jul 2018</p><script>/* eslint-env browser */
</span>}</code></pre><div style="height: 1px;"></div></div></div></div></div></section></div></div></div><p style="text-align: center;" class="text-muted">Generated by&nbsp;<a href="https://github.com/danielgtaylor/aglio" class="aglio">aglio</a>&nbsp;on 26 Jul 2018</p><script>/* eslint-env browser */
/* eslint quotes: [2, "single"] */
'use strict';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment