我是Elastic Search API的新手。我有一个要求,我需要查询和列出强制包含以下属性的文件,比如说
"请求:" / v3?id = 100000" &安培; "输入:" GET"
结果应包含包含上述内容的文档列表。我尝试了以下内容,它可以获得上述任何一项。
{
"query": {
"match": {
"type": "GET"
}
}
}
我试过
{
"query": {
"match": {
"type": "GET",
"request: "/v3/id=100000"
}
}
}
失败了......
有人可以建议我查询列出具有上述属性的所有文档吗?不确定如何使用过滤器,如果我尝试显示失败 - 解析异常。
我的示例文档:
{
"_index": "logstash-2016.04.22",
"_type": "endpoint-access",
"_id": "fAhTQkDRQTiHKlzuleNA",
"_score": null,
"_source": {
"@version": "1",
"@timestamp": "2016-04-22T15:26:35.153Z",
"offset": "43714176",
"ident": "-",
"auth": "-",
"timestamp": "22/Apr/2016:15:26:35 +0000",
"type": "GET",
"request": "/v3?id=1b32e833-b521",
"httpversion": "1.1",
"response": "500",
"bytes": "265",
"referrer": "-",
"agent": "-",
"x_forwarded_for": "\"101.2.123.24\""
"host": "101.123.115.167"
},
"sort": [
1461338795153,
1461338795153
]
}
答案 0 :(得分:1)
您可以使用“必须”来获得结果:
public void test() {
// creates a list of fruits
List<Fruit> fruits = Arrays.asList(
new Fruit("Apple", 10),
new Fruit("Apple", 14),
new Fruit("Pear", 4));
// Old style.
// holds the largest apple so far
Fruit largeApple = null;
for (Fruit fruit : fruits) {
if (fruit.getType().equals("Apple")) {
if (largeApple == null
|| largeApple.size() < fruit.size()) {
largeApple = fruit;
}
}
}
System.out.println("Old: " + largeApple);
// New Style.
Optional<Fruit> max = fruits.stream()
.filter(f -> f.type.equals("Apple"))
.max(Comparator.comparing(f -> f.size));
System.out.println("Lambda: " + max);
}