I am new to Elastic search and I have written code to index a list of City. I am using "elasticsearch head" add-on for chrome to check and manipulate the indexes and _doc.
While indexing and CRUD operation of doc is resulting correctly, I had to delete the index manually via elastic-search add-on.
I want to check for the index first, if an index is available, delete it, and create the index & index the list of City again. This is what I want to do. But getting an error in Delete() method saying
argument 1: cannot convert from string to Nest.IDeleteRequest
Following is my code to show you what I am doing:
public async Task<List<BulkResponseItemBase>> AddNewIndex(string index_name, List<City> model)
{
client = new ElasticClient(elstcstngs);
List<BulkResponseItemBase> elstcManyrespoStatusList = new List<BulkResponseItemBase>();
if (await CheckIndexExists(index_name))
{
//This is where I am getting error - Cannot Convert from string to Nest.IDeleteRequest
client.Delete(index_name);
}
elstcstngs.DefaultMappingFor<City>(m => m.IndexName(index_name));
BulkResponse elstcManyrespoStatus = await client.IndexManyAsync<City>(model, null);
if (elstcManyrespoStatus.Errors)
{
foreach (var itemWithError in elstcManyrespoStatus.ItemsWithErrors)
{
elstcManyrespoStatusList.Add(itemWithError);
System.Diagnostics.Debug.WriteLine("Failed to index document {0}: {1}", itemWithError.Id, itemWithError.Error);
}
}
return elstcManyrespoStatusList;
}
I have searched the Elastic search Documentation but could not find any API in NEST 7.4.1 documentation, which will delete the index itself.
Instead what I am getting is of NEST version 1.x.
Any link towards a documentation or any help regarding the code will very helpful.
Thank you.
As you can see from client.Delete method description
it exposes elasticsearch delete API which is responsible for deleting documents from elasticsearch.
If you want to remove index you can do this with
await client.Indices.DeleteAsync("index_name");
Hope that helps.
Related
im very new to testing and have no training in automated tests so please bare with me if i say stupid things but ill try the best i can.
Bascially i am trying to assert that a specific employee in the employee list has the status of 'leaver'.
This is what i have tried (and other variations with the different classes)
Assert.Equal("image-tile__badge background-color--status-leaver ng-star-inserted", Driver.FindElement(By.XPath("//*[contains(#class,'image-tile__content-header') and contains(text(),'End Date, Contract') and contains(#class, 'image-tile__badge')]")).GetAttribute("Class"));
Assert.Equal("image-tile__badge background-color--status-leaver ng-star-inserted", Driver.FindElement(By.XPath("//*[contains(#class,'image-tile__content-header') and contains(text(),'End Date, Contract')]")).FindElement(By.XPath("//*[contains(#class, 'image-tile__badge')]")).GetAttribute("Class"));
The last one finds the element when the status is 'new', but when i change the employee status to 'leaver', it still returns as 'new' so possibly looking at another employee with a 'new' status.
Hopefully this is enough info, let me know if more is needed (this is my first ever post!)
HTML code in image below
[HTML code on Chrome]
[1]: https://i.stack.imgur.com/kUxkf.png
Summary: im trying to assert that the Employee "End Date, Contract" has the status of leaver (aka the leaver class "image-tile__badge background-color--status-leaver ng-star-inserted")
Thanks everyone for their help!
One of my devs managed to take #noldors example and modify it a bit so heres what ended up working for me:
var newElmList1 = Driver.FindElements(By.CssSelector("div.background-color--status-leaver")).ToList();
List<string> newNames1 = new List<string>();
foreach (var newElm in newElmList1)
{
var newName1 = newElm.FindElement(By.XPath(".."))
.FindElement(By.CssSelector("div.image-tile__content-header")).Text;
newNames.Add(newName1);
}
if (!newNames.Contains("End Date, Contract"))
{
throw new Exception("Exception Error on leaver Person");
}
As per your screenshot i fill it's better if you try using Xpath
var elmList = Driver.FindElements(By.Xpath("//div[contains(text(),'leaver')]")).ToList();
i hope it will help you
Thank You.
According to your screenshot, you can find all elements with 'Leaver' specific class with this;
var leaverElmList = Driver.FindElements(By.CssSelector("div.background-color--status-leaver")).ToList();
List<string> leaverNames = new List<string>();
foreach (var leaverElm in leaverElmList) {
var leaverName = leaverElm.FindElement(By.XPath(".."))
.FindElement(By.CssSelector("div.image-tile__content-header"));
.Text()
leaverNames.Add(leaverName);
}
Enddate, Contract which is not related to the div that contains Leaver. It's direct parent is the image-tile div
I have two large excel files. I am able to get the rows of these excel files into a list using linqtoexcel. The issue is that I need to use a string from one object within the first list to find if it is part of or contained inside another string within an object of the second list. I was trying the following but the process is taking to long as each list is over 70,000 items.
I have tried using an Any statement but have not be able to pull results. If you have any ideas please share.
List<ExcelOne> exOne = new List<ExcelOne>();
List<ExcelTwo> exTwo = new List<ExcelTwo>();
I am able to build the first list and second list and can verify there are objects in the list. Here was my thought of how I would work through the lists to find matching. Note that once I have found the matching I want to create a new class and add it to a new list.
List<NewFormRow> rows = new List<NewFormRow>();
foreach (var item in exOne)
{
//I am going through each item in list one
foreach (var thing in exTwo)
{
//I now want to check if exTwo.importantRow has or
//contains any part of the string from item.id
if (thing.importantRow.Contains(item.id))
{
NewFormRow adding = new NewFormRow()
{
Idfound = item.id,
ImportantRow = thing.importantRow
};
rows.Add(adding);
Console.WriteLine("added one");
}
}
If you know a quicker way around this please share. Thank you.
It's hard to improve this substring approach. The question is if you have to do it here. Can't you do it where you have filled the lists? Then you don't need this additional step.
However, maybe you find this LINQ query more readable:
List<NewFormRow> rows = exOne
.SelectMany(x => exTwo
.Where(x2 => x2.importantRow.Contains(x.id))
.Select(x2 => new NewFormRow
{
Idfound = x.id,
ImportantRow = x2.importantRow
}))
.ToList();
This is a part of the code that i was trying to use to get the respective elements, but it keeps giving me the following error:
System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]or
others identical
This is also shown in a datagridview, in her rows.
IList<IWebElement> ruas = Gdriver.FindElements(By.ClassName("search-title"));
String[] AllText = new String[ruas.Count];
int i = 0;
foreach (IWebElement element in ruas)
{
AllText[i++] = element.Text;
table.Rows.Add(ruas);
}
First thing is: as far as I understand the elements you are talking about are not contained in table. Its a list: <ul class="list-unstyled list-inline">... (considering the comment you left with site link)
If you want to find those elements you can use the code below:
var elements = driver.FindElements(By.CssSelector("ul.list-inline > li > a"));
// Here you can iterate though links and do whatever you want with them
foreach (var element in elements)
{
Console.WriteLine(element.Text);
}
// Here is the collection of links texts
var linkNames = elements.Select(e => e.Text).ToList();
Considering the error you get, I may assume that you are using DataGridView for storing collected data, which is terribly incorrect. DataGridView is used for viewing data in MVC application. There is no standard Selenium class for storing table data. There are multiple approaches for this, but I can't suggest you any because I don't know your what you are trying to achieve.
Here is how i answered my own question:
IList<string> all = new List<string>();
foreach (var element in Gdriver.FindElements(By.ClassName("search-title")))
{
all.Add(element.Text);
table.Rows.Add(element.Text);
}
I am trying to list records on route53 that we have but am failing to get more than the first 100 results! How can I list ALL of them? How can I also filter the results to list only those with a specific RecordType?
This is the code I tried running but I fail to get a complete list…:
string recordList = "";
int ii = 0;
ListResourceRecordSetsResponse result = r53client.ListResourceRecordSets(request);
System.Windows.Forms.MessageBox.Show(result.ListResourceRecordSetsResult.ResourceRecordSets.Count+" records!");
while (result.ListResourceRecordSetsResult.ResourceRecordSets.Count > 0)
{
foreach (var recordSet in result.ListResourceRecordSetsResult.ResourceRecordSets)
{
if (recordSet.Type == "CNAME")
{
foreach (var resourceRecord in recordSet.ResourceRecords)
{
recordList += resourceRecord.Value + "\n";
jj++;
// set first record to get next, as the last one we already got!
request.StartRecordName = resourceRecord.Value;
}
}
}
result = r53client.ListResourceRecordSets(request);
}
From Github: Can you get more than 100 ListResourceRecordSets:
If the response says IsTruncated is true, then you need to pass the values of NextRecordType, NextRecordName, and NextRecordIdentifier back to a new call.
From AWS Command-Line Interface (CLI) documentation for list-resource-record-sets:
To retrieve all the records in a HostedZone, first pause any processes making calls to ChangeResourceRecordSets. Initially call list-resource-record-sets without a Name and Type to get the first page of record sets. For subsequent calls, set Name and Type to the NextName and NextType values returned by the previous response.
From Class ListResourceRecordSetsRequest:
To retrieve all the records in a HostedZone, first pause any processes making calls to ChangeResourceRecordSets. Initially call ListResourceRecordSets without a Name and Type to get the first page of record sets. For subsequent calls, set Name and Type to the NextName and NextType values returned by the previous response.
I am trying to batch insert relationships into neo4j database using the Neo4jclient for c#. I found this code by user dcinzona. I am looking through the latest source code and can't find this class Neo4jDataRespository anywhere. Is this a custom class created by this user or am I missing something?
string merge1 = string.Format("c:{0} {{{1}:row.{2}}}", IDFieldLeft.Replace("Id", ""), IDFieldLeft, IDFieldLeft);
string merge2 = string.Format("a:{0} {{{1}:row.{2}}}", IDFieldRight.Replace("Id", ""), IDFieldRight, IDFieldRight);
string merge3 = string.Format("(c)-[r:{0} {{row}}]->(a)", entityName);
foreach (var list in Neo4jDataRepository.Batch(relationshipMatrix, 1000))
{
var query = client
.Cypher
.WithParam("coll", list.ToList())
.ForEach("(row in {coll})")//manually create json array of list objects
.Merge(merge1)
.Merge(merge2)
.Merge(merge3);
query.ExecuteWithoutResults();
}
This is a custom class created by that user, it's not part of Neo4jClient.
I'm not sure what they've done, and I've not seen it referenced anywhere else but by them I'm afraid :/