Skip to content
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

Integration of ElasticSearch v1.0 (GROUND - 6) #68

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

Integration of ElasticSearch v1.0 (GROUND - 6) #68

wants to merge 36 commits into from

Conversation

nipunramk
Copy link

Added ability to insert into ElasticSearch and get search responses by key values in tags and also by ids. Added a ElasticSearch.java util file in the utils folder with all relevant helper methods. Getting list of ids through a tag key now goes through ElasticSearch. Also set up a TagResources endpoint.

Copy link
Member

@vsreekanti vsreekanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of comments inline. Tests are also failing on the CI build.

pom.xml Outdated
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.5.1</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version should be a variable in the properties field of the POM.

import edu.berkeley.ground.dao.models.NodeVersionFactory;
import edu.berkeley.ground.dao.models.StructureFactory;
import edu.berkeley.ground.dao.models.StructureVersionFactory;
import edu.berkeley.ground.dao.models.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using the Google Java style guide which specifies no * imports.

@@ -28,4 +28,5 @@
public abstract List<Long> getVersionIdsByTag(String tag) throws GroundException;

public abstract List<Long> getItemIdsByTag(String tag) throws GroundException;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unnecessary whitespace.

public List<Long> getVersionIdsByTag(String tag) throws GroundException {
return this.getIdsByTag(tag, "rich_version");
return ElasticSearch.getSearchResponse("rich_version", tag);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a configuration option that allows people to turn on / off ElasticSearch use. Let's add a field to the config and pass it through to the TagFactory. If it's turned off, we can go to the regular database (current impl.), and if it's turned on, we can use the ElasticSearch API.

LOGGER.info("Retrieving all item ids with tag: " + tag + ".");
return this.tagFactory.getItemIdsByTag(tag);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace.

String json = mapper.writeValueAsString(tag);
IndexResponse response = client.prepareIndex(clusterName, table, Long.toString(tag.getId()))
.setSource(json).get();
client.admin().indices().prepareRefresh().execute().actionGet(); // need to refresh index with new inserted item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly does refreshing an index do? Do we need to do it on every insert?

return response.isCreated();

} catch (JsonProcessingException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing the stack trace isn't the right thing to do. We should pass the error information through with the exception that we throw.


public static List<Long> getSearchResponse(String type, String searchQuery) throws GroundException {
SearchResponse response = client.prepareSearch().setTypes(type).setQuery(QueryBuilders.matchQuery("key", searchQuery)).get();
SearchHit[] hits = response.getHits().getHits();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .getHits().getHits() an ES API idiosyncrasy?

import edu.berkeley.ground.dao.models.NodeVersionFactory;
import edu.berkeley.ground.dao.models.StructureFactory;
import edu.berkeley.ground.dao.models.StructureVersionFactory;
import edu.berkeley.ground.dao.models.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No * imports.

@@ -52,7 +54,7 @@
protected static CassandraTagFactory tagFactory;

@BeforeClass
public static void setup() throws GroundDbException {
public static void setup() throws GroundDbException, GroundException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't throw both. GroundDbException is a subclass of GroundException.

@vsreekanti
Copy link
Member

Please also put the name of the JIRA issue (GROUND-6) in square brackets at the beginning of the PR for consistency. :-)

@vsreekanti
Copy link
Member

@nipunramk: Looks like the build is still failing.

@nipunramk nipunramk changed the title Integration of ElasticSearch v1.0 Integration of ElasticSearch v1.0 (GROUND - 6) May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants