Beispiel #1
1
 public bool Delete(string id)
 {
     var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch);
     connectionSettings.SetDefaultIndex("advertisement");
     var elasticClient = new ElasticClient(connectionSettings);
     return elasticClient.Delete(new Nest.DeleteRequest("advertisement", "advertisement", id)).Found;
 }
        /// <summary>
        /// This method removes an index from Elastic
        /// </summary>
        /// <param name="query">IndexRequest containing delete criteria</param>
        /// <returns>IndexResponse indicating success or failure</returns>
        public DataContracts.IndexResponse RemoveDocument(IndexRequest query)
        {
            ESI4TLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager.RemoveDocument for TCM URI: " +
                                 query.ItemURI);
            DataContracts.IndexResponse response   = new DataContracts.IndexResponse();
            JavaScriptSerializer        serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = Int32.MaxValue;
            var             webClient = new WebClient();
            OperationResult result    = OperationResult.Failure;

            try
            {
                XmlDocument doc     = new XmlDocument();
                string      ID      = query.ItemURI;
                string      strId   = "\"" + ID + "\"";
                var         content = webClient.DownloadString(@"http://*****:*****@"\b'\b", "")));
                foreach (var item in data)
                {
                    var aa = item;
                    if (aa.Key == "hits")
                    {
                        foreach (var item2 in aa.Value)
                        {
                            var aaaa = item2;
                            if (aaaa.Key == "hits")
                            {
                                foreach (var item3 in aaaa.Value)
                                {
                                    foreach (var item4 in item3)
                                    {
                                        if (item4.Key == "_id")
                                        {
                                            Id      = item4.Key;
                                            idValue = item4.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //var bln = Deserialize<Esnews>(doc);
                node = new Uri("http://localhost:9200");

                settings = new ConnectionSettings(node);

                settings.DefaultIndex("fromelasticstoweb8");
                var client         = new Nest.ElasticClient(settings);
                var responseReturn = client.Delete <Esnews>(idValue, d => d
                                                            .Index("fromelasticstoweb8")
                                                            .Type("esnews"));
                result = OperationResult.Success;
                ESI4TLogger.WriteLog(ELogLevel.INFO, "Exit ESI4TIndexManager.RemoveDocument for TCM URI: " +
                                     query.ItemURI + " result " + result);
            }
            catch (Exception ex)
            {
                string logString = ESI4TServiceConstants.LOG_MESSAGE + Environment.NewLine;
                logString = string.Concat(logString,
                                          string.Format("Item URI : {0}", query.ItemURI),
                                          Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace));
                ESI4TLogger.WriteLog(ELogLevel.ERROR, logString);
                result = OperationResult.Failure;
            }

            response.Result = (int)result;

            ESI4TLogger.WriteLog(ELogLevel.INFO,
                                 "Exiting ESI4TIndexManager.RemoveDocument, Result: " +
                                 result.ToString());

            return(response);
        }
        private static void Index(DocumentModel document, String operation)
        {
            var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"];
            var searchBoxUri = new Uri(uriString);

            var settings = new ConnectionSettings(searchBoxUri);
            settings.SetDefaultIndex(indexName);

            var client = new ElasticClient(settings);

            if (!client.IndexExists(indexName).Exists)
            {
                // Create a new "sample" index with default settings
                ICreateIndexRequest iCreateIndexReq = new CreateIndexRequest(indexName);
                iCreateIndexReq.IndexSettings = new IndexSettings();
                iCreateIndexReq.IndexSettings.NumberOfReplicas = 10;

                //iCreateIndexReq.IndexSettings.Mappings = new List<RootObjectMapping>();
                //RootObjectMapping rootObjectMapping = new RootObjectMapping();
                //rootObjectMapping.AllFieldMapping()
                //iCreateIndexReq.IndexSettings.Mappings.
                //client.CreateIndex(iCreateIndexReq);
                //client.CreateIndex(indexName,s=>s.)
                var resCreate = client.CreateIndex(indexName, s => s.AddMapping<DocumentModel>(f => f.MapFromAttributes()).NumberOfReplicas(1).NumberOfShards(10));

                //client.CreateIndex(indexName, new IndexSettings());
                //client.create
            }

            if (operation.Equals("delete"))
            {
                //client.DeleteById(indexName, "documents", document.DocumentId);
                IDeleteByQueryRequest iDeleteByQueryRequest = new DeleteByQueryRequest();
                //IDeleteIndexRequest delReq = new DeleteIndexRequest(indexName);
                //client.DeleteIndex()
                //client.DeleteByQuery(new DeleteByQueryRequest())
                client.Delete<DocumentModel>(f => f.Id(document.DocumentId).Index(indexName).Refresh());
                //var response = this.Client.Delete<ElasticsearchProject>(f=>f.Id(newDocument.Id).Index(newIndex).Refresh());
            }
            else
            {
               //IIndexRequest<DocumentModel> indexRequest = IndexRequest<DocumentModel>();
               //client.Index(i)
               //client.Index(document, indexName, "documents", document.DocumentId);
               //IndexDescriptor indexDesc = IndexDescriptor;
               //IndexRequestParameters indexParameter = new IndexRequestParameters();
               // indexParameter.Replication(1);
                client.Index(document, i => i.Id(document.DocumentId).Index(indexName));
                //client.Index();
                //client.Index()
            }
        }
Beispiel #4
0
 public bool Delete(string id)
 {
     var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch);
     connectionSettings.SetDefaultIndex("websites");
     connectionSettings.MapDefaultTypeNames(m => m.Add(typeof(websites), "list"));
     var elasticClient = new ElasticClient(connectionSettings);
     return elasticClient.Delete(new Nest.DeleteRequest("websites", "list", id)).Found;
 }