-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Can use external ES mapping instead of push mapping #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can use external ES mapping instead of push mapping #233
Conversation
dd4bf0c to
a33d9df
Compare
amcp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments
| Settings.Builder settings = Settings.builder(); | ||
| if(useExternalMappings){ | ||
| throw new IllegalArgumentException("Could not create index: " + indexName); | ||
| }else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces before and after else
| if (!client.indexExists(indexName)) { | ||
|
|
||
| Settings.Builder settings = Settings.builder(); | ||
| if(useExternalMappings){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces after if and before the open brace
| (map==Mapping.PREFIX_TREE && AttributeUtil.isGeo(dataType)), | ||
| "Specified illegal mapping [%s] for data type [%s]",map,dataType); | ||
|
|
||
| if(useExternalMappings){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing
| } catch (IOException e) { | ||
| throw new PermanentBackendException(e); | ||
| } | ||
| }else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing
| try { | ||
| //We check if the externalMapping have the property 'key' | ||
| Map mappings = client.getMapping(indexName, store); | ||
| if(!mappings.containsKey(key)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing
|
|
||
| import java.util.Map; | ||
|
|
||
| public class RestIndexMappings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add classdoc
a33d9df to
9a05a35
Compare
|
@sjudeng I think I just unblocked this PR |
|
@davidclement90 Please rebase on master now that your other PR has been merged (thanks @amcp) and then I can add a review as well. |
bdb4079 to
8aed813
Compare
|
Thanks for the code style updates on #233. |
sjudeng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another great contribution! Some comments below. On the minor code style side can you double check your indentation is consistently four spaces everywhere?
| private void checkForOrCreateIndex(Configuration config) throws IOException { | ||
| Preconditions.checkState(null != client); | ||
|
|
||
| //Create index if it does not already exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment (it's copied inside the below if-then).
| Preconditions.checkState(null != client); | ||
|
|
||
| //Create index if it does not already exist | ||
| if (!client.indexExists(indexName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra nesting level by combining if-thens.
if (!client.indexExists(indexName) && !useExternalMappings) {
//Create index if it does not already exist
} else if (!client.indexExists(indexName)) {
throw new IllegalArgumentException("Could not create index: " + indexName);
}| port = getInterface() == ElasticSearchSetup.REST_CLIENT ? 9200 : 9300; | ||
| httpClient = HttpClients.createDefault(); | ||
| try { | ||
| host = new HttpHost(InetAddress.getByName("127.0.0.1"), 9200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use four spaces for indentation
| Configuration indexConfig = config.restrictTo(INDEX_NAME); | ||
| FileInputStream fis = null; | ||
| try { | ||
| //Test create index KO mapping is not push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use four spaces for indentation
| assertTrue(res.getStatusLine().getStatusCode() >= 200); | ||
| assertTrue(res.getStatusLine().getStatusCode() < 300); | ||
| assertFalse(EntityUtils.toString(res.getEntity()).contains("error")); | ||
| }finally{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} finally {
|
|
||
| private void executeRequest(HttpRequestBase request) throws IOException { | ||
| CloseableHttpResponse res = null; | ||
| try{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try {
| public static final ConfigOption<Boolean> USE_EXTERNAL_MAPPINGS = | ||
| new ConfigOption<Boolean>(ES_CREATE_NS, "use-external-mappings", | ||
| "When JanusGraph register an index, JanusGraph can push the mapping or use an external mapping. " + | ||
| "Enabling this option make JanusGraph use an external mapping.", ConfigOption.Type.MASKABLE, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For description how about just "Whether JanusGraph should make use of an external mapping when registering an index." Or if you prefer yours make a few corrections: s/register/registers/, s/, JanusGraph/ it/ and s/make/makes/
| public Map getMapping(String indexName, String typeName) throws IOException{ | ||
| Response response = performRequest("GET", "/" + indexName.toLowerCase() + "/_mapping/"+typeName, null); | ||
| try (final InputStream inputStream = response.getEntity().getContent()) { | ||
| Map<String,Map<String,Map<String,RestIndexMappings>>> settings = mapper.readValue(inputStream, new TypeReference<Map<String, Map<String,Map<String,RestIndexMappings>>>>() {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation to four spaces. Also you can update RestIndexMappings as shown in separate comment below and then you can simplify this deserialization code as follows.
Map<String,RestIndexMappings> settings = mapper.readValue(inputStream, new TypeReference<Map<String,RestIndexMappings>>() {});
return settings.get(indexName).getMappings().get(typeName).getProperties();| public void setProperties(Map<String, Object> properties) { | ||
| this.properties = properties; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this (single-type) mapping object down to inner class and use outer object for the (multi-type) mappings object.
public class RestIndexMappings {
private Map<String,RestIndexMapping> mappings;
public Map<String, RestIndexMapping> getMappings() {
return mappings;
}
public void setMappings(Map<String, RestIndexMapping> mappings) {
this.mappings = mappings;
}
public static class RestIndexMapping {
private Map<String,Object> properties;
public Map<String, Object> getProperties() {
return properties;
}
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
}
}732343c to
7833bb0
Compare
| public static final ConfigOption<Boolean> USE_EXTERNAL_MAPPINGS = | ||
| new ConfigOption<Boolean>(ES_CREATE_NS, "use-external-mappings", | ||
| "Whether JanusGraph should make use of an external mapping when registering an index." + | ||
| "Enabling this option make JanusGraph use an external mapping.", ConfigOption.Type.MASKABLE, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the second sentence ("Enabling this option...") or else add a space after the preceding period and change "make" to "makes".
7833bb0 to
403bf01
Compare
|
@amcp Since it looks like you're looking over PRs now (thanks!!) can you also approve and/or merge this one if your comments are addressed? |
|
|
||
| public static final ConfigNamespace ELASTICSEARCH_NS = | ||
| new ConfigNamespace(INDEX_NS, "elasticsearch", "Elasticsearch index configuration"); | ||
| new ConfigNamespace(INDEX_NS, "elasticsearch", "Elasticsearch index configuration"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove rogue spaces at end of line
| port = getInterface() == ElasticSearchSetup.REST_CLIENT ? 9200 : 9300; | ||
| httpClient = HttpClients.createDefault(); | ||
| try { | ||
| host = new HttpHost(InetAddress.getByName("127.0.0.1"), 9200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you get the port on line 88 but ignore the value and use 9200 across the board. is this ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's ok. Even if JanusGraph talks to Elasticsearch with the tranport API over port 9300, the mapping or the template are pushed with the REST API over port 9200.
|
@davidclement90 @sjudeng I caught some more things as I reviewed the latest update. |
Signed-off-by: David Clement <david.clement90@laposte.net>
403bf01 to
5ffcdb6
Compare
…seExternalMapping Can use external ES mapping instead of push mapping
…seExternalMapping Can use external ES mapping instead of push mapping
This adds the possibility to use external mapping in order to use custom ES mapping.
If you set USE_EXTERNAL_MAPPINGS to true, JanusGraph will check if the mapping is good instead of push it.
Whitout this adds, even if I push a mapping JanusGraph will update it during register phase.
This feature will allows to manage mapping directly in Kibana and not with ES_CREATE_EXTRAS_NS properties or to set for example a property with are declare in JanusGraph as String to IP, or use copy-to ES feature.
Issue : #222
Signed-off-by: David Clement david.clement90@laposte.net