-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to query Graph Analytics views (#4148)
- Loading branch information
1 parent
625b63e
commit f16eef7
Showing
11 changed files
with
346 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...cala/ch/epfl/bluebrain/nexus/delta/plugins/graph/analytics/GraphAnalyticsViewsQuery.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.graph.analytics | ||
|
||
import akka.http.scaladsl.model.Uri | ||
import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.client.ElasticSearchClient | ||
import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchViewRejection | ||
import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchViewRejection.WrappedElasticSearchClientError | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.SortList | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef | ||
import io.circe.{Json, JsonObject} | ||
import monix.bio.IO | ||
|
||
/** Allows to perform elasticsearch queries on Graph Analytics views */ | ||
trait GraphAnalyticsViewsQuery { | ||
|
||
/** | ||
* In a given project, perform the provided elasticsearch query on the projects' Graph Analytics view. | ||
* @param projectRef | ||
* project in which to make the query | ||
* @param query | ||
* elasticsearch query to perform on the Graph Analytics view | ||
* @param qp | ||
* the extra query parameters for the elasticsearch index | ||
*/ | ||
def query(projectRef: ProjectRef, query: JsonObject, qp: Uri.Query): IO[ElasticSearchViewRejection, Json] | ||
} | ||
|
||
/** | ||
* A [[GraphAnalyticsViewsQuery]] implementation that uses the [[ElasticSearchClient]] to query views. | ||
* @param prefix | ||
* prefix used in the names of the elasticsearch indices | ||
* @param client | ||
* elasticsearch client | ||
*/ | ||
class GraphAnalyticsViewsQueryImpl(prefix: String, client: ElasticSearchClient) extends GraphAnalyticsViewsQuery { | ||
override def query(projectRef: ProjectRef, query: JsonObject, qp: Uri.Query): IO[ElasticSearchViewRejection, Json] = { | ||
val index = GraphAnalytics.index(prefix, projectRef) | ||
client.search(query, Set(index.value), qp)(SortList.empty).mapError(WrappedElasticSearchClientError) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
docs/src/main/paradox/docs/delta/api/assets/graph-analytics/ga-search.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"hits": { | ||
"hits": [ | ||
{ | ||
"_id": "http://example.com/person", | ||
"_index": "delta_ga_myorg_myproj", | ||
"_score": 1.3121864, | ||
"_source": { | ||
"@id": "http://example.com/person", | ||
"@type": "http://schema.org/Person", | ||
"properties": [ | ||
{ | ||
"@id": "http://example.com/epfl", | ||
"dataType": "object", | ||
"isInArray": false, | ||
"path": "http://schema.org/worksFor" | ||
} | ||
], | ||
"references": [ | ||
{ | ||
"@id": "http://example.com/epfl", | ||
"@type": [ | ||
"http://schema.org/EducationalOrganization" | ||
], | ||
"dataType": "object", | ||
"found": true, | ||
"isInArray": false, | ||
"path": "http://schema.org/worksFor" | ||
} | ||
], | ||
"relationships": [ | ||
{ | ||
"@id": "http://example.com/epfl", | ||
"@type": [ | ||
"http://schema.org/EducationalOrganization" | ||
], | ||
"dataType": "object", | ||
"isInArray": false, | ||
"path": "http://schema.org/worksFor" | ||
} | ||
], | ||
"_createdAt": "2023-08-08T15:49:14.081Z", | ||
"_createdBy": { | ||
"@type": "User", | ||
"realm": "internal", | ||
"subject": "delta" | ||
}, | ||
"_deprecated": false, | ||
"_project": "myorg/myproj", | ||
"_rev": 1, | ||
"_updatedAt": "2023-08-08T15:49:14.081Z", | ||
"_updatedBy": { | ||
"@type": "User", | ||
"realm": "internal", | ||
"subject": "delta" | ||
} | ||
} | ||
} | ||
], | ||
"max_score": 1.3121864, | ||
"total": { | ||
"relation": "eq", | ||
"value": 1 | ||
} | ||
}, | ||
"timed_out": false, | ||
"took": 0, | ||
"_shards": { | ||
"failed": 0, | ||
"skipped": 0, | ||
"successful": 1, | ||
"total": 1 | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
docs/src/main/paradox/docs/delta/api/assets/graph-analytics/ga-search.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
curl -XPOST \ | ||
-H "Content-Type: application/json" \ | ||
"http://localhost:8080/v1/graph-analytics/myorg/myproj/_search" -d \ | ||
'{ | ||
"query": { | ||
"term": { | ||
"@id": "https://example.com/person" | ||
} | ||
} | ||
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.