如何在Kibana中查询字段中的布尔值?

时间:2016-10-14 15:10:36

标签: elasticsearch kibana-4

我正在使用Kibana 4,我知道使用字符串值搜索字段,我可以使用field_value:Test之类的查询。

但是如果一个字段是布尔类型,我就不能像is_new:true那样搜索。

我应该使用什么声明?

1 个答案:

答案 0 :(得分:0)

抱歉,我发现我使用了错误的字段名称。 import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.Date; public class Test{ public static void main(String[] arguments) { String sDateString = "2016-02-14 20:10:10"; String eDateString = "2016-02-15 20:10:10"; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date startDate = null, endDate = null; try { startDate = df.parse(sDateString); endDate = df.parse(eDateString); } catch (Exception e) { e.printStackTrace(); } //difference in milliseconds long diff = endDate.getTime() - startDate.getTime(); //difference in days System.out.println(diff/(3600*24*1000)); /////////////////////////////////////////////////////////////// //Alternatively , use java 8 LocalDate startLocalDate = LocalDateFromDate(startDate); LocalDate endLocalDate = LocalDateFromDate(endDate); //difference in days System.out.println(ChronoUnit.DAYS.between(startLocalDate, endLocalDate)); /////////////////////////////////////////////////////////////// //Alternatively, if the String representation of date is fixed //you can extract the string representing the day of the month //not recommended) //find index 0f last "-" int sIndex = sDateString.lastIndexOf("-"); //get the day in month substring, remove spaces String s = sDateString.substring(sIndex+1,sIndex+3).trim(); int eIndex = sDateString.lastIndexOf("-"); String e = eDateString.substring(sIndex+1,sIndex+3).trim(); //difference in days System.out.println(Integer.parseInt(e) - Integer.parseInt(s)); } public static LocalDate LocalDateFromDate(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()) .toLocalDate(); } } 有效