Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.sail.elasticsearch;
import java.io.IOException;
import java.net.InetAddress;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.vocabulary.GEOF;
import org.eclipse.rdf4j.query.MalformedQueryException;
import org.eclipse.rdf4j.query.algebra.Var;
import org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex;
import org.eclipse.rdf4j.sail.lucene.BulkUpdater;
import org.eclipse.rdf4j.sail.lucene.DocumentDistance;
import org.eclipse.rdf4j.sail.lucene.DocumentResult;
import org.eclipse.rdf4j.sail.lucene.DocumentScore;
import org.eclipse.rdf4j.sail.lucene.LuceneSail;
import org.eclipse.rdf4j.sail.lucene.SearchDocument;
import org.eclipse.rdf4j.sail.lucene.SearchFields;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.health.ClusterIndexHealth;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.index.reindex.DeleteByQueryAction;
import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.locationtech.spatial4j.context.SpatialContext;
import org.locationtech.spatial4j.context.SpatialContextFactory;
import org.locationtech.spatial4j.distance.DistanceUtils;
import org.locationtech.spatial4j.io.GeohashUtils;
import org.locationtech.spatial4j.shape.Point;
import org.locationtech.spatial4j.shape.Shape;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.Iterables;
/**
* Requires an Elasticsearch cluster with the DeleteByQuery plugin.
*
* @see LuceneSail
*/
public class ElasticsearchIndex extends AbstractSearchIndex {
/**
* Set the parameter "indexName=" to specify the index to use.
*/
public static final String INDEX_NAME_KEY = "indexName";
/**
* Set the parameter "documentType=" to specify the document type to use. By default, the document type is
* "resource".
*/
public static final String DOCUMENT_TYPE_KEY = "documentType";
/**
* Set the parameter "transport=" to specify the address of the cluster to use (e.g. localhost:9300).
*/
public static final String TRANSPORT_KEY = "transport";
/**
* Set the parameter "waitForStatus=" to configure if {@link #initialize(java.util.Properties) initialization}
* should wait for a particular health status. The value can be one of "green" or "yellow". Does not wait by
* default.
*/
public static final String WAIT_FOR_STATUS_KEY = "waitForStatus";
/**
* Set the parameter "waitForNodes=" to configure if {@link #initialize(java.util.Properties) initialization} should
* wait until the specified number of nodes are available. Does not wait by default.
*/
public static final String WAIT_FOR_NODES_KEY = "waitForNodes";
/**
* Set the parameter "waitForActiveShards=" to configure if {@link #initialize(java.util.Properties) initialization}
* should wait until the specified number of shards to be active. Does not wait by default.
*/
public static final String WAIT_FOR_ACTIVE_SHARDS_KEY = "waitForActiveShards";
/**
* Set the parameter "waitForRelocatingShards=" to configure if {@link #initialize(java.util.Properties)
* initialization} should wait until the specified number of nodes are relocating. Does not wait by default.
*
* @deprecated use {@link #WAIT_FOR_NO_RELOCATING_SHARDS_KEY} in elastic search >= 5.x
*/
@Deprecated
public static final String WAIT_FOR_RELOCATING_SHARDS_KEY = "waitForRelocatingShards";
/**
* Set the parameter "waitForNoRelocatingShards=true|false" to configure if {@link #initialize(java.util.Properties)
* initialization} 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.
*/
public static final String WAIT_FOR_NO_RELOCATING_SHARDS_KEY = "waitForNoRelocatingShards";
public static final String DEFAULT_INDEX_NAME = "elastic-search-sail";
public static final String DEFAULT_DOCUMENT_TYPE = "resource";
public static final String DEFAULT_TRANSPORT = "localhost";
public static final String DEFAULT_ANALYZER = "standard";
public static final String ELASTICSEARCH_KEY_PREFIX = "elasticsearch.";
public static final String PROPERTY_FIELD_PREFIX = "p_";
public static final String ALL_PROPERTY_FIELDS = "p_*";
public static final String GEOPOINT_FIELD_PREFIX = "_geopoint_";
public static final String GEOSHAPE_FIELD_PREFIX = "_geoshape_";
private final Logger logger = LoggerFactory.getLogger(getClass());
private volatile TransportClient client;
private String clusterName;
private String indexName;
private String documentType;
private String analyzer;
private String queryAnalyzer = "standard";
private Function super String, ? extends SpatialContext> geoContextMapper;
public ElasticsearchIndex() {
}
public String getClusterName() {
return clusterName;
}
public String getIndexName() {
return indexName;
}
public String[] getTypes() {
return new String[] { documentType };
}
@SuppressWarnings("unchecked")
@Override
public void initialize(Properties parameters) throws Exception {
super.initialize(parameters);
indexName = parameters.getProperty(INDEX_NAME_KEY, DEFAULT_INDEX_NAME);
documentType = parameters.getProperty(DOCUMENT_TYPE_KEY, DEFAULT_DOCUMENT_TYPE);
analyzer = parameters.getProperty(LuceneSail.ANALYZER_CLASS_KEY, DEFAULT_ANALYZER);
// slightly hacky cast to cope with the fact that Properties is
// Map