This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticsearch_dsl.search import Search | |
search = Search(using="default", index=index, doc_type=["doc"]) | |
# we only want warning log in this instance | |
search = search.filter('term', level='warning') | |
# we look for results whose text includes the query "invalid argument" | |
search = search.query("multi_match", query="invalid argument", fields=["response.message", "stacktrace"], type="most_prefix") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticsearch_dsl import Date, Document, Keyword, Nested, Text, Integer | |
class HttpLog(Document): | |
"""The schema for a Log document.""" | |
level = Keyword() | |
request = Nested(properties={"body": Text(analyzer="snowball"), "headers": Keyword(), "arguments": Keyword()}) | |
response = Nested(properties={"message": Text(analyzer="snowball"), "status": Integer()}) | |
timestamp = Date() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
int count = schools.count(); | |
double average = allHeights.average() | |
// java | |
int count = schools.count(); | |
OptionalDouble average = allHeights.average(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
schools.ForEach(s => s.set_address("test address")); | |
// java | |
schools.forEach(s -> s.set_address("test address")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
IEnumerable<IGrouping<int, IEnumerable<Student>>> studentsGrouppedByYear = studentsInAllSchools.GroupBy(s => s.get_year()); | |
// java | |
Map<Integer, List<Student>> studentsGrouppedByYear = studentsInAllSchools.collect(Collectors.groupingBy(s -> s.get_year())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
IEnumerable<Student> studentsInFirstYear = studentsInAllSchools.Where(s => s.get_year() == 1); | |
// java | |
Stream<Student> studentsInFirstYear = studentsInAllSchools.filter(s -> s.get_year() == 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
bool doAllStudentsExceed100cmInHeight = studentsInAllSchools.All(s => s.get_height() > 100); | |
// java | |
boolean doAllStudentsExceed100cmInHeight = studentsInAllSchools.allMatch(s -> s.get_height() > 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
bool doesThisStudentExist = studentsInAllSchools.Any(s => s.get_name() == "Alex"); | |
// java | |
boolean doesThisStudentExist = studentsInAllSchools.anyMatch(s -> s.get_name() == "Alex"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
List<Student> studentsInAllSchools = studentsInAllSchools.ToList(); | |
// java | |
List<Student> studentsInAllSchoolsList = studentsInAllSchools.collect(Collectors.toList()); | |
// or, if you specifically want an arrayList.. | |
List<Student> studentsInAllSchoolsArrayList = studentsInAllSchools.collect(Collectors.toCollection(ArrayList::new)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
IEnumerable<Student> studentsInAllSchools = schools.SelectMany(s => s.get_students()); | |
// java | |
Stream<Student> studentsInAllSchools = schools.flatMap(s -> s.get_students()); |
NewerOlder