public void Get_New_Client_Returns_A_New_Client_When_Called() { var newClient = ElasticSearchClient.GetNewClient(); Assert.IsNotNull(newClient); Assert.IsInstanceOfType(newClient, typeof(ElasticClient)); }
public static IEnumerable <string> Get_ElasticSearchFields(IModelElasticSearchField elasticSearchField) { if (elasticSearchField != null) { var modelElasticSearchFieldList = elasticSearchField.Parent as IModelElasticSearchFieldList; if (modelElasticSearchFieldList != null) { var modelElasticSearchFieldsItem = modelElasticSearchFieldList.Parent as IModelElasticSearchFieldsItem; if (modelElasticSearchFieldsItem != null) { var typeInfo = modelElasticSearchFieldsItem.TypeInfo; if (typeInfo != null && typeInfo.Type != null) { var esFields = new HashSet <string>(); foreach (var ti in typeInfo.DescendantsAndSelf(t => t.Descendants)) { esFields.UnionWith(ElasticSearchClient.ElasticSearchFields(ti.Type, true)); } return(esFields); } } } } return(Enumerable.Empty <string>()); }
public int CreateStock(Stocks stock) { int _newStockid = 0; try { ReadStock createdData = new ReadStock(); ESGetDetail createdESData = new ESGetDetail(); ElasticSearchClient createES = new ElasticSearchClient(); createdData = _dataAccessLayer.CreateDbStock(stock); string cacheKey = CreateKey(createdData.ID); using (MemcachedClient client = new MemcachedClient("memcached")) { client.Store(StoreMode.Add, cacheKey, createdData, DateTime.Now.AddMinutes(15)); } createdESData = ConvertCachetoESData(createdData); //getCreatedData = Mapper.Map<ReadStock, ESGetDetail>(getCreatedData); createES.CreateESStock(createdESData); _newStockid = createdESData.ID; } catch (Exception) { throw; } return(_newStockid); }
public HangingRequestsHandler( ElasticSearchClient <IndexRequestDbo> elasticClient, ElasticSearchOptions elasticOptions) { _elasticClient = elasticClient; _elasticOptions = elasticOptions; }
public IActionResult Get(string id) { var client = new ElasticSearchClient <IIndexedEntities>(_settings, new BackgroundBaseContext(id, "get:product")); var product = client.GetProduct(id); return(new JsonResult(product)); }
public void SimpleTests() { var indexName = "myindex_" + Guid.NewGuid(); var indexType = "type"; var client = new ElasticSearchClient("localhost"); var result = client.Index(indexName, indexType, "testkey", "{\"a\":\"b\",\"c\":\"d\"}"); Assert.AreEqual(true, result.Success); client.Refresh(indexName); var doc = client.Search(indexName, indexType, "c:d"); Console.WriteLine(doc.Response); Assert.AreEqual(1, doc.GetHits().Hits.Count); Assert.AreEqual("b", doc.GetHits().Hits[0].Source["a"]); client.Delete(indexName, indexType, "testkey"); client.Refresh(indexName); var doc1 = client.Get(indexName, indexType, "testkey"); Assert.AreEqual(null, doc1); client.DeleteIndex(indexName); }
public QueueForIndex(ElasticSearchClient <IndexRequestDbo> client, ElasticSearchOptions options) { _client = client; _options = options; EnsureIndexInElasticCreated(); }
public void TestCreateParentChildType() { var index = "index_test_parent_child_type"; var parentType = new TypeSetting("blog"); parentType.AddStringField("title"); var client = new ElasticSearchClient("localhost"); client.CreateIndex(index); var op = client.PutMapping(index, parentType); Assert.AreEqual(true, op.Acknowledged); var childType = new TypeSetting("comment", parentType); childType.AddStringField("comments"); op = client.PutMapping(index, childType); Assert.AreEqual(true, op.Acknowledged); var mapping = client.GetMapping(index, "comment"); Assert.True(mapping.IndexOf("_parent") > 0); client.DeleteIndex(index); }
public AnalyzeTest(ElasticSearchClient currentElasticSearchInstance, string indexName) { InitializeComponent(); this.currentElasticSearchInstance = currentElasticSearchInstance; this.indexName = indexName; this.button1.Visible = false; }
/// <inheritdoc/> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { if (member == null) { throw new ArgumentNullException(nameof(member)); } var jp = base.CreateProperty(member, memberSerialization); var bti = BYteWareTypeInfo.GetBYteWareTypeInfo(member.DeclaringType); var props = bti.ESProperties(member.Name); jp.PropertyName = ElasticSearchClient.FieldName(string.IsNullOrEmpty(props?.FieldName) ? member.Name : props.FieldName); var defType = ElasticSearchClient.GetFieldTypeFromType(member.Type()); // Omit empty values, because Suggest Fields will raise errors otherwise if (defType == FieldType.text || defType == FieldType.keyword) { if (typeof(IEnumerable).IsAssignableFrom(member.Type())) { jp.ShouldSerialize = t => (member.Get(t) as IEnumerable)?.Cast <object>().Any() ?? false; } else { jp.ShouldSerialize = t => !string.IsNullOrEmpty(member.Get(t)?.ToString()); } } if (!string.IsNullOrEmpty(props.WeightField)) { jp.PropertyType = typeof(object); jp.ValueProvider = new SuggestWeightFieldValueProvider(member, jp.PropertyName); } return(jp); }
public HomeController() { restfulClient = new RESTfulClient(); graphQLClient = new GraphQLClient(); personMailGraphVMCreator = new CorrespondenceAnalysisVMCreator(); elasticSearchClient = new ElasticSearchClient(personMailGraphVMCreator, restfulClient); }
private IEnumerable <string> ESFieldsInternal(bool wildcards) { foreach (var p in GetTopPropertyInfos) { var props = ESProperties(p.Name); var propertyName = ElasticSearchClient.FieldName(string.IsNullOrEmpty(props?.FieldName) ? p.Name : props.FieldName); if (props != null && !props.OptOut) { var etype = props.FieldType ?? ElasticSearchClient.GetFieldTypeFromType(p.PropertyType); foreach (var item in ElasticSearchFieldsInternal(p, propertyName, etype, wildcards)) { yield return(item); } var modelESField = props as IModelMemberElasticSearchField; var multiFields = modelESField != null ? modelESField.Fields : Attribute.GetCustomAttributes(p, typeof(ElasticMultiFieldAttribute), true).OfType <IElasticSearchFieldProperties>(); foreach (var ga in multiFields.GroupBy(t => t.FieldName)) { var a = ga.First(); foreach (var item in ElasticSearchFieldsInternal(p, a.FieldName.ToLowerInvariant(), a.FieldType ?? ElasticSearchClient.GetFieldTypeFromType(p.PropertyType), wildcards)) { yield return(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", propertyName, item)); } } } } }
public void SearchAfterTest() { var elasticClient = new ElasticSearchClient( new HttpClient(), Environment.GetEnvironmentVariable("ELASTICSEARCH_API_ENDPOINT_FOUNDATION"), Environment.GetEnvironmentVariable("ELASTICSEARCH_API_KEY_GONZALEZ_ART_FOUNDATION_ADMIN")); var result = elasticClient.SendToElasticSearch( HttpMethod.Get, "/classification/_search", ElasticSearchRequest.GetSearchRequestBody( "", "Sir Lawrence Alma-Tadema", 100, null) ).Result; var resultAfter = elasticClient.SendToElasticSearch( HttpMethod.Get, "/classification/_search", ElasticSearchRequest.GetSearchRequestBody( "", "Sir Lawrence Alma-Tadema", 100, JObject.Parse(result)["hits"]["hits"].Last["sort"] ) ).Result; }
private void InitTree(string clusterName, ElasticSearchClient instance) { var model = new TreeModel(); if (instance != null) { var indices = instance.Status(); if (indices == null) { throw new ServerException("can't connect to server"); } currentCluster = clusterName; currentElasticSearchInstance = instance; var node = new ElasticNode(clusterName); model.Root.Nodes.Add(node); var sortedIndices = indices.IndexStatus.OrderBy(d => d.Key); foreach (var index in sortedIndices) { var tempNode = new ElasticNode(string.Format("{0} ({1})", index.Key, index.Value.DocStatus.NumDocs)); tempNode.ElasticSearchInstance = instance; tempNode.Tag = index; tempNode.IndexName = index.Key; tempNode.IndexStatus = index.Value; node.Nodes.Add(tempNode); } } treeViewAdv1.Model = model; treeViewAdv1.Refresh(); }
public void GivenDifferentTypesOfTenureTypes(string firstName, string lastName, List <string> list) { var listOfPersons = new List <QueryablePerson>(); foreach (var tenureType in list) { listOfPersons.Add(new QueryablePerson { Firstname = firstName, Surname = lastName, Tenures = new List <QueryablePersonTenure> { new QueryablePersonTenure { Type = tenureType } } }); } var awaitable = ElasticSearchClient.IndexManyAsync(listOfPersons, INDEX).ConfigureAwait(true); while (!awaitable.GetAwaiter().IsCompleted) { } Thread.Sleep(5000); }
public void TestBulkForFramdThrift() { var client = new ElasticSearchClient("localhost"); var fields = new Dictionary <string, object>(); fields.Add("name", "jack"); fields.Add("age", 25); var index = "index_bulk_framed"; try { client.DeleteIndex(index); client.CreateIndex(index); } catch (Exception e) { Console.WriteLine(e); } var jsondata = JsonSerializer.Get(fields); var result = client.Bulk(new List <BulkObject>() { new BulkObject() { Id = "1", Index = index, Type = "type", JsonData = jsondata }, new BulkObject() { Id = "2", Index = index, Type = "type", JsonData = jsondata }, new BulkObject() { Id = "3", Index = index, Type = "type", JsonData = jsondata }, new BulkObject() { Id = "4", Index = index, Type = "type", JsonData = jsondata }, new BulkObject() { Id = "5", Index = index, Type = "type", ParentId = "1", JsonData = jsondata }, new BulkObject() { Id = "6", Index = index, Type = "type", ParentId = "1", JsonData = jsondata }, new BulkObject() { Id = "7", Index = index, Type = "type", ParentId = "1", JsonData = jsondata }, new BulkObject() { Id = "8", Index = index, Type = "type", ParentId = "1", JsonData = jsondata }, }); Assert.AreEqual(true, result.Success); }
public Function( IAmazonDynamoDB dbClient, IAmazonS3 s3Client, ElasticSearchClient elasticSearchClient) { DbClient = dbClient; S3Client = s3Client; ElasticSearchClient = elasticSearchClient; }
public Reindexer( ElasticSearchClient <IndexRequestDbo> requestsClient, ElasticSearchOptions options, QueueForIndex queueForIndex) { _requestsClient = requestsClient; _options = options; _queueForIndex = queueForIndex; }
public IActionResult Search(SearchModel search) { if (search.query != null) { ElasticSearchClient esClient = new ElasticSearchClient(); search.models = esClient.Search(search.query).Select(x => (SearchResultViewModel)x).ToList(); } return(View("Index", search)); }
public IndexingCore( IAmazonDynamoDB dbClient, IAmazonS3 s3Client, ElasticSearchClient elasticSearchClient) { DbClient = dbClient; S3Client = s3Client; ElasticSearchClient = elasticSearchClient; }
public void SetUp() { _fileData = new FileDataTest() { Checksum = "123", Content = "test", Path = new List <string> { @"c:\test\test.txt" } }; _elasticSearchClient = new ElasticSearchClient(new ServerInfo("localhost", 9200)); }
/// <summary> /// reload tree /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void aDDToolStripMenuItem_Click(object sender, EventArgs e) { if (connect.ShowDialog() == DialogResult.OK) { var srcClient = new ElasticSearchClient(connect.Host, connect.Port, connect.Type); var cluster = string.Format("{0}:{1}", connect.Host, connect.Port); InitTree(cluster, srcClient); //DuplicateCheck(); } }
public void TestDynamicUserClusters() { ElasticSearchClient client = new ElasticSearchClient("127.0.0.1", 9200, TransportType.Http); List <string> indices = client.GetIndices(); client = new ElasticSearchClient("127.0.0.1", 9500, TransportType.Thrift, true); indices = client.GetIndices(); }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (toolStripComboBox1.Text != null && !string.IsNullOrEmpty(toolStripComboBox1.Text)) { string clusterName = toolStripComboBox1.Text; var srcClient = new ElasticSearchClient(clusterName); InitTree(clusterName, srcClient); } }
/// <summary> /// Returns the name of the WeightFieldMember /// </summary> /// <param name="esField">IModelMemberElasticSearchField instance</param> /// <param name="value">FieldType value</param> public static void Set_FieldType(IModelMemberElasticSearchField esField, FieldType?value) { if (esField != null) { if (value.HasValue && esField.Parent is IModelMember member && string.IsNullOrEmpty(esField.FieldName)) { esField.FieldName = ElasticSearchClient.FieldName(member.Name); } ((ModelNode)esField).SetValue <FieldType?>(nameof(IModelMemberElasticSearchField.FieldType), value); } }
/// <summary> /// Initializes a new instance of the <see cref="TypeMappingWriter"/> class. /// internal constructor by TypeMappingWriter itself when it recurses, passes seenTypes as safeguard against maxRecursion /// </summary> /// <param name="ec">ElasticSearchClient instance</param> /// <param name="bti">Type to create the mapping for</param> /// <param name="maxRecursion">Maximum number of recursions for nested types</param> /// <param name="optOut">Was the type marked as opting out of ElasticSearch indexing</param> /// <param name="baseType">Type Info for the base class</param> /// <param name="seenTypes">Already visited types</param> internal TypeMappingWriter(ElasticSearchClient ec, BYteWareTypeInfo bti, int maxRecursion, bool optOut, BYteWareTypeInfo baseType, ConcurrentDictionary <Type, int> seenTypes) { byteWareTypeInfo = bti; baseBWTypeInfo = baseType; elasticSearchClient = ec; MaxRecursion = maxRecursion; OptOut = optOut; SeenTypes = seenTypes; }
/// <summary> /// Returns the Name of the Parameter whose value should be used for the context that was defined through the Suggest attribute /// </summary> /// <param name="suggestContext">IModelElasticSearchSuggestContext instance</param> /// <returns>Name of the Parameter whose value should be used for the context that was defined through the Suggest attribute</returns> public static string Get_DefaultParameter(IModelElasticSearchSuggestContext suggestContext) { if (suggestContext != null) { var typeInfo = suggestContext.TypeInfo; if (typeInfo != null && typeInfo.Type != null) { return(ElasticSearchClient.ElasticSearchSuggestFieldContextParameter(typeInfo, suggestContext.ModelElasticSearchSuggestField.ElasticSearchSuggestField, suggestContext.Name)); } } return(null); }
private static void MapFieldProperties(ElasticAttribute pa, IElasticSearchFieldProperties field, IModelMember member) { MapInterfaceProperties <IElasticSearchFieldProperties>(pa, field); if (string.IsNullOrWhiteSpace(field.FieldName)) { field.FieldName = ElasticSearchClient.FieldName(member.Name); } if (!field.FieldType.HasValue) { field.FieldType = ElasticSearchClient.GetFieldTypeFromType(member.Type); } }
/// <summary> /// Returns a List of potential ElasticSearch Suggest field names /// </summary> /// <param name="suggestField">IModelElasticSearchSuggestField instance</param> /// <returns>List of potential ElasticSearch Suggest field names</returns> public static IList <string> Get_ElasticSearchSuggestFields(IModelElasticSearchSuggestField suggestField) { if (suggestField != null && suggestField.Parent is IModelElasticSearchSuggestFieldList modelElasticSearchSuggestFieldList && modelElasticSearchSuggestFieldList.Parent is IModelElasticSearchFieldsItem modelElasticSearchFieldsItem) { var typeInfo = modelElasticSearchFieldsItem.TypeInfo; if (typeInfo != null && typeInfo.Type != null) { return(ElasticSearchClient.ElasticSearchSuggestFields(typeInfo).ToList()); } } return(new List <string>()); }
public PostMapping(ElasticSearchClient currentElasticSearchInstance, string index, string type) { InitializeComponent(); jsonViewer = new JsonViewer(); jsonViewer.ShowTab(Tabs.Viewer); jsonViewer.Dock = DockStyle.Fill; panel2.Controls.Add(jsonViewer); textBox1.Text = index; textBox2.Text = type; this.currentElasticSearchInstance = currentElasticSearchInstance; }
public ElasticSearchAppender() { Client = new ElasticSearchClient(); Index = "qptlogs"; Type = "m"; }
public ElasticSearchMessageQueue() { EsClient = new ElasticSearchClient(); Index = "messaging"; Type = "message"; }