Панда, эквивалентная
select * from table where column_name = some_value
, является
table[table.column_name == some_value]
Множественные условия:
table[(table.column_name == some_value) | (table.column_name2 == some_value2)]
или
table.query('column_name == some_value | column_name2 == some_value2')
import pandas as pd
# Create data set
d = {'foo':[100, 111, 222],
'bar':[333, 444, 555]}
df = pd.DataFrame(d)
# Full dataframe:
df
# Shows:
# bar foo
# 0 333 100
# 1 444 111
# 2 555 222
# Output only the row(s) in df where foo is 222:
df[df.foo == 222]
# Shows:
# bar foo
# 2 555 222
В приведенном выше коде это строка df[df.foo == 222]
, которая дает строки на основе значения столбца, 222
в этом case.
Возможны также множественные условия:
df[(df.foo == 222) | (df.bar == 444)]
# bar foo
# 1 444 111
# 2 555 222
Но в этот момент я бы рекомендовал использовать функцию query , так как он менее подробный и дает тот же результат:
df.query('foo == 222 | bar == 444')
Идея:
Сначала прочитайте из корня, создайте классы карты из корня. Взял, TimedOut, Осколки и Хиты.
Во-вторых, ваши классы предназначены для "hit.hits". И это массив, поэтому ему нужен IEnumerable вроде List. Пожалуйста, завершите это самостоятельно, добавив [PropertyName ("...")] по мере необходимости:
public class OuterHits
{
public string total {get;Set;}
public string max_score {get;Set;}
public List<RawDocument> hits {get;Set;} // or hits[]
}
Также вам может понадобиться корневой класс
public class rootClass
{
public string string took {get;Set;}
public string timeout {get;Set;}
public Shards shards {get;Set;}
public OuterHits hits {get;Set;}
}
Также реализуйте класс Shards [ 116]
Как указывает @Russ Cam, приведенное ниже обновление решения публикуется в качестве ответа для обзора другими.
public class RawDocument
{
[PropertyName("duration")]
public long Duration { get; set; }
[PropertyName("group_id")]
public string GroupId { get; set; }
[PropertyName("var_time")]
public DateTime Vartime { get; set; }
[PropertyName("var_name")]
public string Varname { get; set; }
}
static void Main(string[] args)
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultMappingFor<RawDocument>(m => m
.IndexName("test_index")
.TypeName("doc"));
var searchResponse = client.Search<RawDocument>();
var numberOfSlices = 4;
var scrollAllObservable = client.ScrollAll<RawDocument>("3m", numberOfSlices)
.Wait(TimeSpan.FromMinutes(5), onNext: s =>
{
var docs = s.SearchResponse.DebugInformation;
var documents = s.SearchResponse.Hits;
foreach (var document in documents)
{
// do something with this set of documents
// business logic to load into the database.
MessageBox.Show("document.Id=" + document.Id);
MessageBox.Show("document.Score=" + document.Score);
MessageBox.Show("document.Source.duration=" + document.Source.duration);
MessageBox.Show("document.Source.var_time=" + document.Source.var_time);
MessageBox.Show("document.Source.var_name=" + document.Source.var_name);
MessageBox.Show("document.Type=" + document.Type);
MessageBox.Show("document.Index=" + document.Index);
}
});
}