-
Notifications
You must be signed in to change notification settings - Fork 86
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
Elasticsearch implementation #658
base: develop
Are you sure you want to change the base?
Conversation
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.
A couple comments/questions here. I'm completely ignorant to how elastix works so these are get-my-feet-wet questions.
config/dev.exs
Outdated
@@ -51,6 +51,10 @@ config :code_corps, :analytics, CodeCorps.Analytics.InMemoryAPI | |||
config :code_corps, :stripe, Stripe | |||
config :code_corps, :stripe_env, :dev | |||
|
|||
# Configure elasticsearch | |||
config :code_corps, :elasticsearch_url, "http://0.0.0.0: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.
Maybe should set these URLs via ENV vars?
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.
That makes sense. I had put these in the config files initially for convenience.
config/dev.exs
Outdated
@@ -51,6 +51,10 @@ config :code_corps, :analytics, CodeCorps.Analytics.InMemoryAPI | |||
config :code_corps, :stripe, Stripe | |||
config :code_corps, :stripe_env, :dev | |||
|
|||
# Configure elasticsearch | |||
config :code_corps, :elasticsearch_url, "http://0.0.0.0:9200" | |||
config :code_corps, :elasticsearch_index, "skills" |
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.
Is there a reason we should be setting these indexes in the config?
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.
We shouldn't. I had put these in the config files initially for convenience. But it needs to go away.
Elastix provides basic functionality for working with elasticsearch. It's a pretty small library (4 modules) and not very long or complex. |
mix.exs
Outdated
@@ -4,7 +4,7 @@ defmodule CodeCorps.Mixfile do | |||
def project do | |||
[app: :code_corps, | |||
version: "0.0.1", | |||
elixir: "1.3.4", | |||
elixir: "1.4.0", |
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.
Looks like the circleci is failing because of this, would undo for the PR as the upgrade to 1.4 should probably be in its own PR
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.
Good point, overlooked that. I'll do that this evening.
web/helpers/elastic_search_helper.ex
Outdated
def to_map(foo, bar), do: %{ String.to_atom(foo) => bar} | ||
|
||
defp settings_map do | ||
%{ |
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.
Indentation
This looks awesome! Great job. One thing I would suggest is maybe making the |
Thanks for the kind words. I like the ideas you proposed and think they should work. I'll start working on those ideas soon. |
Hey @paulsullivanjr I just wanted to check in on this and see if there's anything we should be doing here? |
@joshsmith I want to discuss what other steps and pieces we'll need to integrate this. I'll catch up with you on slack tonight or tomorrow. I want to get this done so I can get started other other issues. |
Awesome, I will be around to discuss. |
Hey @paulsullivanjr just adding that suggestions comment here for context to this PR:
|
web/helpers/elastic_search_helper.ex
Outdated
@@ -47,7 +47,7 @@ defmodule CodeCorps.ElasticSearchHelper do | |||
end | |||
|
|||
def process_response(%HTTPoison.Response{status_code: 200} = response, type) do | |||
response.body["hits"]["hits"] |> Enum.map(fn(x) -> x["_source"][type] end) | |||
response.body["hits"]["hits"] |> Enum.map(fn(x) -> x["_source"] end) |
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.
What is x
here? I think this variable could benefit from a longer name.
web/controllers/skill_controller.ex
Outdated
@@ -18,4 +22,9 @@ defmodule CodeCorps.SkillController do | |||
|> title_filter(params) | |||
|> limit_filter(params) | |||
end | |||
|
|||
def search(_conn, params) do | |||
CodeCorps.ElasticSearchHelper.search(@elasticsearch_url, @elasticsearch_index, @elasticsearch_type, query) |
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.
Looks like query
is undefined here.
web/controllers/skill_controller.ex
Outdated
@@ -23,7 +23,7 @@ defmodule CodeCorps.SkillController do | |||
|> limit_filter(params) | |||
end | |||
|
|||
def search(_conn, params) do | |||
def search(_conn, %{"query" => query} = params) do |
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 can remove the = params
portion here if you're not using the params
as a whole object.
We could easily get
|
- Removed duplicate entry - Moved some code and a couple small refactors of the helper module - Updated to not pass the document index when creating - cleaning up some unneeded changes - Updated search function - Changed elixir version back to 1.3.4 - Updates per comments, added add_documents() function to helper - added some convenience functions - Removing unnecessary code, eliminated 1.4 warning messages so it's done when we upgrade - Added tests for fuzzy search, updates some map formats - Added match all function - Added search endpoint for elasticsearch, updated to return maps - Added comment about using -- with lists
9291262
to
31cd82c
Compare
488d755
to
46dfe17
Compare
e075407
to
6d6cc63
Compare
What's in this PR?
This is currently work in progress. But wanted to get an initial PR out.
References
Fixes #60