Elasticsearch Nest - Querying Aliases - elasticsearch

Does the Elasticsearch NEST API expose access to /{index}/{_aliases}/*? I am trying to get a list of indexes mapped to a given alias and I cannot seem to find an appropriate method.
{
"ntdev-events017-v1": {
"aliases": {
"ntdev-events017": {}
}
}
}
http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html

You can use GetAlias method on ElasticClient.
Take a look on this example:
var indexName = "sampleindex";
var uri = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(uri).SetDefaultIndex(indexName).EnableTrace();
var client = new ElasticClient(settings);
client.CreateIndex(descriptor => descriptor.Index(indexName));
var putAliasResponse = client.PutAlias(descriptor => descriptor
.Index(indexName).Name("alias1"));
var putAliasResponse2 = client.PutAlias(descriptor => descriptor
.Index(indexName).Name("alias2"));
var aliasesForIndex = client.GetAlias(descriptor => descriptor
.Index(indexName))
.Indices[indexName]
.Select(x => x.Name).ToList();
var indexesMappedToAlias = client.GetAlias(descriptor => descriptor.Alias("alias2"))
.Indices.Select(x => x.Key).ToList();

Related

Can nested loops be used in Cypress?

I would like to know if Cypress supports nested loops?
In my case, I have a table where I need to iterate over each row (row is represented by the "data-automationid="DetailsRowFields"") and then over each cell.
Although I attempted to create a function that would extract it, I am unsure if it can be done.
export function getCellData() : Promise<Map<string, string>> {
return new Cypress.Promise((resolve) => {
const cellMap = new Map<string, string>();
cy.get('div[data-automationid="DetailsRowFields"]')
.each((rowElement) => {
rowElement.children()
.each((child) => {
const ariaIndex = child.attr('aria-colindex');
const cellData = child.text();
cellMap.set(ariaIndex, cellData);
});
})
.then(() => resolve(cellMap));
});
}
That won't quite work as you expect, you will only get the last row data.
The Map key should include the row index.
Also, rowElement is a jQuery object. While jQuery does have methods for .children() and .each(), the calling pattern is different to the equivalent Cypress .each().
I recommend wrapping the rowElement.
const cellMap = new Map<string, string>();
cy.get('div[data-automationid="DetailsRowFields"]')
.each((rowElement, rowIndex) => {
cy.wrap(rowElement)
.children()
.each((child) => {
const ariaIndex = child.attr('aria-colindex');
const cellData = child.text();
const mapKey = `${rowIndex}:${ariaIndex}`
cellMap.set(mapKey, cellData);
})
})

how to get all documents by index in Easticsearch using NEST?

I want to GET all my documents by Index. I have tried the following:
var response = client.Search(s => s.Index("test").MatchAll());
the response returns "successful operation" but it hits no document despite the fact that there are many documents under that index.
To get all documents within an index, you'll want to use the Scroll API. Note that depending on how many documents we're talking about, it's likely that you'll receive them in batches through multiple HTTP requests/responses.
There's a helper in NEST for making this easier, ScrollAll()
Time processTimePerScroll = "20s";
int numberOfSlices = Environment.ProcessorCount;
var scrollAllObservable = client.ScrollAll<Person>(processTimePerScroll, numberOfSlices, sc => sc
.MaxDegreeOfParallelism(numberOfSlices)
.Search(s => s
.Query(q => q
.MatchAll()
)
)
)
var waitHandle = new ManualResetEvent(false);
Exception exception = null;
var scrollAllObserver = new ScrollAllObserver<Person>(
onNext: response =>
{
// do something with the documents
var documents = response.SearchResponse.Documents;
},
onError: e =>
{
exception = e;
waitHandle.Set();
},
onCompleted: () => waitHandle.Set()
);
scrollAllObservable.Subscribe(scrollAllObserver);
waitHandle.WaitOne();
if (exception != null)
{
throw exception;
}

How Can i Search on Elasticsearch 5x

I created an object and i want to search this object as an fields value. There is no problem Elasticsearch connection. also i can get all data when i use AllIndices. but i cannot get a value when search as a field. What is the problem? i follow the own Elasticsearch document.
This is My Code
var person = new Person
{
Id = 3,
Firstname = "TOM",
Lastname = "Brandly"
};
if (!client.IndexExists("person").Exists)
{
client.CreateIndex("person");
}
var indexResponse = client.Index(person);
var searchResult = client.Search<Person>(s => s
.From(0)
.Size(10)
.Query(q => q
.Term(p => p.Firstname, "TOM")));

ReactiveUI Testing

I am attempting to see if the results of a view model are performing the correct actions.
My observables are setup as follows:
public FilterBoxViewModel()
{
var asyncFilterResults = this.filterItemsCommand.RegisterAsyncTask(x =>
this.PerformFilter(x as string));
this.filteredItems = new ObservableAsPropertyHelper<IEnumerable<IFilterBoxItem>>(
asyncFilterResults, _ => this.RaisePropertyChanged("FilteredItems"));
this.WhenAnyValue(x => x.SearchTerm)
.Throttle(TimeSpan.FromMilliseconds(50))
.Skip(1)
.Subscribe(this.filterItemsCommand.Execute);
}
Then further down I have
private async Task<IEnumerable<IFilterBoxItem>> PerformFilter(string searchTerm)
{
if (string.IsNullOrWhiteSpace(searchTerm))
{
return Enumerable.Empty<IFilterBoxItem>();
}
// Perform getting the items on the main thread and async await the results.
// This is provide a immutable version of the results so we don't cause
// threading issues.
var items = await Observable.Start(
() => this.FilterBoxManager.RootElements.GetAllItemsEnumerable()
.ToList().Select(x => new { Name = x.Name, Item = x }),
RxApp.MainThreadScheduler);
return
items.Where(x =>
x.Name.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0)
.Select(x => x.Item);
}
In my test, I am running the test schedular and advancing it, however, I am getting the PerformFilter performing at different times than I expect
eg my test is:
(new TestScheduler()).With(scheduler =>
{
var viewModel = new FilterBoxViewModel();
var testManager = new TestManager { RootElements = this.sampleItems };
viewModel.FilterBoxManager = testManager;
viewModel.SearchTerm = "folder";
scheduler.AdvanceBy(TimeSpan.FromMilliseconds(51).Ticks);
Assert.AreEqual(viewModel.FilteredItems.Select(x => x.Name), folderSearchResults);
viewModel.SearchTerm = "apple";
Assert.AreEqual(viewModel.FilteredItems.Select(x => x.Name), appleSearchResults);
});
How do I make the tester more predictable?
I am running ReactiveUI 5.5.1 and in a XAML application.
Your Throttle doesn't set a scheduler, this is a classic TestScheduler mistake

Wp7 & ReactiveOauth

I´m having trouble populating a list with the result from an API using ReactiveOauth for wp7.
It works when i´m populating the listbox directly. But I can´t figure out how to add the object to a list instead. The list is always empty when doing it like this .Subscribe(a => lista.Add(new Device ...
Any suggestions is very appreciated.
var token = TelldusWrapper.Security.GetToken();
var lista = new List<Device>();
var client = new OAuthClient(ConsumerKey, ConsumerSecret, token)
{
Url = "http://api.telldus.com/xml/devices/list",
Parameters = { { "supportedMethods", "TELLSTICK_TURNON" } }
};
client.GetResponseText().Select(s => XElement.Parse(s))
.SelectMany(x => x.Descendants("device"))
.Select(x => new
{
Text = x.Attribute("id").Value,
Name = x.Attribute("name").Value
})
.ObserveOnDispatcher()
.Subscribe(a => listbox.Items.Add(new Device { Id = a.Text, Name = a.Name }), ex => MessageBox.Show(ex.ToString()));
//.Subscribe(a => lista.Add(new Device { Id = a.Text, Name = a.Name }), ex => MessageBox.Show(ex.ToString()));

Resources