public static List <SearchReturnData> SearchMoreStructData(ElasticClient client, String indexName, String mappingType, String fieldName, String key) { StructFilesData structFilesData = SearchStructData(client, indexName, mappingType, fieldName, key); List <SearchReturnData> list = new List <SearchReturnData>(); AddData(list, structFilesData.DayFiles, TimeRange.天.ToString()); AddData(list, structFilesData.WeekFiles, TimeRange.周.ToString()); AddData(list, structFilesData.MonthFiles, TimeRange.月.ToString()); AddData(list, structFilesData.YearFiles, TimeRange.年.ToString()); return(list); }
public static StructFilesData SearchStructData(ElasticClient client, String indexName, String mappingType, String fieldName, String key) { String rangeYear = DateTime.Now.Year + ""; String day = (DateTime.Now.Day - 1) + ""; String week = (DateTime.Now.DayOfWeek - 1) + ""; String month = DateTime.Now.Month + ""; String year = (DateTime.Now.Year - 1) + ""; var structFilesCls = new StructFilesData(); var daysearchResult = client.Search <SearchReturnData>(s => s .Index(indexName) .Type(mappingType) .Query(q => q.MatchAll() && Query <object> .MatchPhrase(mp => mp.OnField("structName").Query(key)) && Query <object> .MatchPhrase(mp => mp.OnField("timeRange").Query(TimeRange.天.ToString())) && Query <object> .MatchPhrase(mp => mp.OnField("rangeYear").Query(rangeYear)) && Query <object> .MatchPhrase(mp => mp.OnField("rangeValue").Query(day)) //.Bool(m => m.Must(mq=>mq.MatchAll(),Query<object>.MatchPhrase(mp => mp.OnField("structName").Query(key))) // .Must(Query<object>.MatchPhrase(mp => mp.OnField("timeRange").Query(TimeRange.天.ToString()))) // .Must(Query<object>.MatchPhrase(mp => mp.OnField("rangeYear").Query(rangeYear))) // .Must(Query<object>.MatchPhrase(mp => mp.OnField("rangeValue").Query(day))) //) ) .SearchType(SearchType.DfsQueryAndFetch) ); var dayReturnInfoClses = new SearchReturnData[daysearchResult.HitsMetaData.Hits.Count]; for (var i = 0; i < daysearchResult.HitsMetaData.Hits.Count; i++) { dayReturnInfoClses[i] = daysearchResult.HitsMetaData.Hits[i].Source; } structFilesCls.DayFiles = dayReturnInfoClses; var weeksearchResult = client.Search <SearchReturnData>(s => s .Index(indexName) .Type(mappingType) .Query(q => q.MatchAll() && Query <object> .MatchPhrase(mp => mp.OnField("structName").Query(key)) && Query <object> .MatchPhrase(mp => mp.OnField("timeRange").Query(TimeRange.周.ToString())) && Query <object> .MatchPhrase(mp => mp.OnField("rangeYear").Query(rangeYear)) && Query <object> .MatchPhrase(mp => mp.OnField("rangeValue").Query(week)) //.Bool(m => m.Must(Query<object>.Term("structName", key)) // .Must(Query<object>.Term("timeRange", TimeRange.周.ToString())) // .Must(Query<object>.Term("rangeYear", rangeYear)) // .Must(Query<object>.Term("rangeValue", week)) //) ) .SearchType(SearchType.DfsQueryAndFetch) ); var weekReturnInfoClses = new SearchReturnData[weeksearchResult.HitsMetaData.Hits.Count]; for (var i = 0; i < weeksearchResult.HitsMetaData.Hits.Count; i++) { weekReturnInfoClses[i] = weeksearchResult.HitsMetaData.Hits[i].Source; } structFilesCls.WeekFiles = weekReturnInfoClses; var monthsearchResult = client.Search <SearchReturnData>(s => s .Index(indexName) .Type(mappingType) .Query(q => q.MatchAll() && Query <object> .MatchPhrase(mp => mp.OnField("structName").Query(key)) && Query <object> .MatchPhrase(mp => mp.OnField("timeRange").Query(TimeRange.月.ToString())) && Query <object> .MatchPhrase(mp => mp.OnField("rangeYear").Query(rangeYear)) && Query <object> .MatchPhrase(mp => mp.OnField("rangeValue").Query(month)) //.Bool(m => m.Must(Query<object>.Term("structName", key)) // .Must(Query<object>.Term("timeRange", TimeRange.月.ToString())) // .Must(Query<object>.Term("rangeYear", rangeYear)) // .Must(Query<object>.Term("rangeValue", month)) //) ) .SearchType(SearchType.DfsQueryAndFetch) ); var monthReturnInfoClses = new SearchReturnData[monthsearchResult.HitsMetaData.Hits.Count]; for (var i = 0; i < monthsearchResult.HitsMetaData.Hits.Count; i++) { monthReturnInfoClses[i] = monthsearchResult.HitsMetaData.Hits[i].Source; } structFilesCls.MonthFiles = monthReturnInfoClses; var yearsearchResult = client.Search <SearchReturnData>(s => s .Index(indexName) .Type(mappingType) .Query(q => q.MatchAll() && Query <object> .MatchPhrase(mp => mp.OnField("structName").Query(key)) && Query <object> .MatchPhrase(mp => mp.OnField("timeRange").Query(TimeRange.年.ToString())) && Query <object> .MatchPhrase(mp => mp.OnField("rangeYear").Query(rangeYear)) && Query <object> .MatchPhrase(mp => mp.OnField("rangeValue").Query(year)) //.Bool(m => m.Must(Query<object>.Term("structName", key)) // .Must(Query<object>.Term("timeRange", TimeRange.年.ToString())) // .Must(Query<object>.Term("rangeYear", rangeYear)) // .Must(Query<object>.Term("rangeValue", year)) //) ) .SearchType(SearchType.DfsQueryAndFetch) ); var yearReturnInfoClses = new SearchReturnData[yearsearchResult.HitsMetaData.Hits.Count]; for (var i = 0; i < yearsearchResult.HitsMetaData.Hits.Count; i++) { yearReturnInfoClses[i] = yearsearchResult.HitsMetaData.Hits[i].Source; } structFilesCls.YearFiles = yearReturnInfoClses; return(structFilesCls); }