Class ElasticsearchIndex
java.lang.Object
org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
org.eclipse.rdf4j.sail.elasticsearch.ElasticsearchIndex
- All Implemented Interfaces:
SearchIndex
Requires an Elasticsearch cluster with the DeleteByQuery plugin.
Note that, while RDF4J is licensed under the EDL, several ElasticSearch dependencies are licensed under the Elastic
license or the SSPL, which may have implications for some projects.
Please consult the ElasticSearch website and license FAQ for more information.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
Set the parameter "documentType=" to specify the document type to use.static final String
static final String
static final String
static final String
Set the parameter "indexName=" to specify the index to use.static final String
static final String
Set the parameter "transport=" to specify the address of the cluster to use (e.g.static final String
Set the parameter "waitForActiveShards=" to configure ifinitialization
should wait until the specified number of shards to be active.static final String
Set the parameter "waitForNoRelocatingShards=true|false" to configure ifinitialization
should wait until the are no relocating shards.static final String
Set the parameter "waitForNodes=" to configure ifinitialization
should wait until the specified number of nodes are available.static final String
Deprecated.static final String
Set the parameter "waitForStatus=" to configure ifinitialization
should wait for a particular health status.Fields inherited from class org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
maxDocs, wktFields
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
void
begin()
Begins a transaction.void
clear()
Clears the indexes.void
clearContexts
(Resource... contexts) This should be called from within a begin-commit-rollback block.void
commit()
Commits any changes done to the LuceneIndex since the last commit.The semantics is synchronous to SailConnection.commit(), i.e.protected SearchDocument
protected com.google.common.base.Function
<? super String, ? extends org.locationtech.spatial4j.context.SpatialContext> createSpatialContextMapper
(Map<String, String> parameters) protected void
protected Iterable
<? extends DocumentDistance> geoQuery
(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, String distanceVar, Var contextVar) protected Iterable
<? extends DocumentResult> geoRelationQuery
(String relation, IRI geoProperty, String wkt, Var contextVar) protected SearchDocument
getDocument
(String id) Returns a Document representing the specified document ID (combination of resource and context), or null when no such Document exists yet.getDocument
(Resource subject, Resource context) Returns a Document representing the specified Resource and Context combination, or null when no such Document exists yet.protected Iterable
<? extends SearchDocument> getDocuments
(String resourceId) Iterable
<? extends SearchDocument> getDocuments
(Resource subject) Returns a list of Documents representing the specified Resource (empty when no such Document exists yet).Each document represent a set of statements with the specified Resource as a subject, which are stored in a specific contextgetPropertyFields
(Set<String> fields) Filters the given list of fields, retaining all property fields.protected org.locationtech.spatial4j.context.SpatialContext
getSpatialContext
(String property) String[]
getTypes()
void
initialize
(Properties parameters) protected BulkUpdater
protected SearchDocument
newDocument
(String id, String resourceId, String context) protected Iterable
<? extends DocumentScore> Parse the passed query.void
rollback()
org.elasticsearch.search.SearchHits
search
(Resource resource, org.elasticsearch.action.search.SearchRequestBuilder request, org.elasticsearch.index.query.QueryBuilder query) Evaluates the given query only for the given resource.org.elasticsearch.search.SearchHits
search
(org.elasticsearch.action.search.SearchRequestBuilder request, org.elasticsearch.index.query.QueryBuilder query) Evaluates the given query and returns the results as a TopDocs instance.void
shutDown()
protected void
Methods inherited from class org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
accept, addDocuments, addRemoveStatements, addStatement, evaluate, getIndexedTypeMapping, getResource, isGeoField, isIndexedTypeStatement, isTypeFilteringEnabled, isTypeStatement, parseLuceneQueryShape, parseQueryPoint, parseQueryShape, removeStatement
-
Field Details
-
INDEX_NAME_KEY
Set the parameter "indexName=" to specify the index to use.- See Also:
-
DOCUMENT_TYPE_KEY
Set the parameter "documentType=" to specify the document type to use. By default, the document type is "resource".- See Also:
-
TRANSPORT_KEY
Set the parameter "transport=" to specify the address of the cluster to use (e.g. localhost:9300).- See Also:
-
WAIT_FOR_STATUS_KEY
Set the parameter "waitForStatus=" to configure ifinitialization
should wait for a particular health status. The value can be one of "green" or "yellow". Does not wait by default.- See Also:
-
WAIT_FOR_NODES_KEY
Set the parameter "waitForNodes=" to configure ifinitialization
should wait until the specified number of nodes are available. Does not wait by default.- See Also:
-
WAIT_FOR_ACTIVE_SHARDS_KEY
Set the parameter "waitForActiveShards=" to configure ifinitialization
should wait until the specified number of shards to be active. Does not wait by default.- See Also:
-
WAIT_FOR_RELOCATING_SHARDS_KEY
Deprecated.useWAIT_FOR_NO_RELOCATING_SHARDS_KEY
in elastic search >= 5.xSet the parameter "waitForRelocatingShards=" to configure ifinitialization
should wait until the specified number of nodes are relocating. Does not wait by default.- See Also:
-
WAIT_FOR_NO_RELOCATING_SHARDS_KEY
Set the parameter "waitForNoRelocatingShards=true|false" to configure ifinitialization
should wait until the are no relocating shards. Defaults to false, meaning the operation does not wait on there being no more relocating shards. Set to true to wait until the number of relocating shards in the cluster is 0.- See Also:
-
DEFAULT_INDEX_NAME
- See Also:
-
DEFAULT_DOCUMENT_TYPE
- See Also:
-
DEFAULT_TRANSPORT
- See Also:
-
DEFAULT_ANALYZER
- See Also:
-
ELASTICSEARCH_KEY_PREFIX
- See Also:
-
PROPERTY_FIELD_PREFIX
- See Also:
-
ALL_PROPERTY_FIELDS
- See Also:
-
GEOPOINT_FIELD_PREFIX
- See Also:
-
GEOSHAPE_FIELD_PREFIX
- See Also:
-
-
Constructor Details
-
ElasticsearchIndex
public ElasticsearchIndex()
-
-
Method Details
-
getClusterName
-
getIndexName
-
getTypes
-
initialize
- Specified by:
initialize
in interfaceSearchIndex
- Overrides:
initialize
in classAbstractSearchIndex
- Throws:
Exception
-
createSpatialContextMapper
-
getMappings
- Throws:
IOException
-
getSpatialContext
- Specified by:
getSpatialContext
in classAbstractSearchIndex
-
shutDown
- Throws:
IOException
-
getDocument
Returns a Document representing the specified document ID (combination of resource and context), or null when no such Document exists yet.- Specified by:
getDocument
in classAbstractSearchIndex
- Throws:
IOException
-
getDocuments
- Specified by:
getDocuments
in classAbstractSearchIndex
- Throws:
IOException
-
newDocument
- Specified by:
newDocument
in classAbstractSearchIndex
-
copyDocument
- Specified by:
copyDocument
in classAbstractSearchIndex
-
addDocument
- Specified by:
addDocument
in classAbstractSearchIndex
- Throws:
IOException
-
updateDocument
- Specified by:
updateDocument
in classAbstractSearchIndex
- Throws:
IOException
-
deleteDocument
- Specified by:
deleteDocument
in classAbstractSearchIndex
- Throws:
IOException
-
newBulkUpdate
- Specified by:
newBulkUpdate
in classAbstractSearchIndex
-
getDocument
Returns a Document representing the specified Resource and Context combination, or null when no such Document exists yet.- Parameters:
subject
-context
-- Returns:
- search document
- Throws:
IOException
-
getDocuments
Returns a list of Documents representing the specified Resource (empty when no such Document exists yet).Each document represent a set of statements with the specified Resource as a subject, which are stored in a specific context- Parameters:
subject
-- Returns:
- list of documents
- Throws:
IOException
-
getPropertyFields
-
begin
-
commit
Description copied from interface:SearchIndex
Commits any changes done to the LuceneIndex since the last commit.The semantics is synchronous to SailConnection.commit(), i.e. the LuceneIndex should be committed/rolled back whenever the LuceneSailConnection is committed/rolled back.- Throws:
IOException
-
rollback
- Throws:
IOException
-
query
protected Iterable<? extends DocumentScore> query(Resource subject, QuerySpec spec) throws MalformedQueryException, IOException Parse the passed query.- Specified by:
query
in classAbstractSearchIndex
- Parameters:
subject
-spec
- query to process- Returns:
- the parsed query
- Throws:
MalformedQueryException
IOException
IllegalArgumentException
- if the spec contains a multi-param query
-
search
public org.elasticsearch.search.SearchHits search(Resource resource, org.elasticsearch.action.search.SearchRequestBuilder request, org.elasticsearch.index.query.QueryBuilder query) Evaluates the given query only for the given resource.- Parameters:
resource
-request
-query
-- Returns:
- search hits
-
geoQuery
protected Iterable<? extends DocumentDistance> geoQuery(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, String distanceVar, Var contextVar) throws MalformedQueryException, IOException - Specified by:
geoQuery
in classAbstractSearchIndex
- Throws:
MalformedQueryException
IOException
-
geoRelationQuery
protected Iterable<? extends DocumentResult> geoRelationQuery(String relation, IRI geoProperty, String wkt, Var contextVar) throws MalformedQueryException, IOException - Specified by:
geoRelationQuery
in classAbstractSearchIndex
- Throws:
MalformedQueryException
IOException
-
search
public org.elasticsearch.search.SearchHits search(org.elasticsearch.action.search.SearchRequestBuilder request, org.elasticsearch.index.query.QueryBuilder query) Evaluates the given query and returns the results as a TopDocs instance. -
clearContexts
Description copied from interface:SearchIndex
This should be called from within a begin-commit-rollback block.- Parameters:
contexts
-- Throws:
IOException
-
clear
-
WAIT_FOR_NO_RELOCATING_SHARDS_KEY
in elastic search >= 5.x