- end)
- |> List.flatten()
-
- Elastix.Bulk.post(
- url(),
- d,
- index: "activities",
- type: "activity"
- )
- end
-
- defp parse_term(t) do
- if String.contains?(t, ":") and !String.starts_with?(t, "\"") do
- [field, query] = String.split(t, ":")
- if Enum.member?(@searchable, field) do
- {field, query}
- else
- {"content", query}
- end
+ end)
+ |> List.flatten()
+
+ with {:ok, %{body: %{"errors" => false}}} <-
+ Elastix.Bulk.post(
+ url(),
+ d,
+ index: "users",
+ type: "user"
+ ) do
+ :ok
+ else
+ {:error, %{reason: err}} ->
+ Logger.error("Could not bulk put users: #{err}")
+ :skipped
+
+ {:ok, %{body: _}} ->
+ :skipped
+ end
+ end
+
+ def bulk_post(data, :hashtags) when is_list(data) do
+ d =
+ data
+ |> Enum.map(fn d ->
+ [
+ %{index: %{_id: DocumentMappings.Hashtag.id(d)}},
+ DocumentMappings.Hashtag.encode(d)
+ ]
+ end)
+ |> List.flatten()
+
+ with {:ok, %{body: %{"errors" => false}}} <-
+ Elastix.Bulk.post(
+ url(),
+ d,
+ index: "hashtags",
+ type: "hashtag"
+ ) do
+ :ok
+ else
+ {:error, %{reason: err}} ->
+ Logger.error("Could not bulk put hashtags: #{err}")
+ :skipped
+
+ {:ok, %{body: _}} ->
+ :skipped
+ end
+ end
+
+ def bulk_post(_, :hashtags), do: {:ok, nil}
+
+ def search(_, _, _, :skip), do: []
+
+ def search(:raw, index, type, q) do
+ with {:ok, raw_results} <- Elastix.Search.search(url(), index, [type], q) do
+ results =
+ raw_results
+ |> Map.get(:body, %{})
+ |> Map.get("hits", %{})
+ |> Map.get("hits", [])
+
+ {:ok, results}