我需要数据的多重过滤方面的帮助。例如,对于下面的示例JSON,哪种查询最适合?如果我只需要搜索所有字段,例如“ Apple”和水果“ Y”
1)
{
"_index": "abc",
"_type": "123",
{
"field" : "Apple"
"fruit" : "Y"
},
{
"field" : "Tomato"
"fruit" : "N"
},
{
"field" : "Mango"
"fruit" : "Y"
}
2)
{
"_index": "abc",
"_type": "123",
{
"field" : "Apple"
"fruit" : "N"
},
{
"field" : "Tomato"
"fruit" : "Y"
},
{
"field" : "Mango"
"fruit" : "Y"
}
答案 0 :(得分:0)
可能您想研究ES search docs和ES Filters
希望这可以帮助您了解进行搜索的想法:
{
"bool": {
"must": { "match": { "tweet": "elasticsearch" }},
"must_not": { "match": { "name": "mary" }},
"should": { "match": { "tweet": "full text" }},
"filter": { "range": { "age" : { "gt" : 30 }} }
}
}
要完全匹配,您可以use 'term' from ES docs为:
{
"bool": {
"must": [ { "term": { "field": "Apple" }},
{ "term": { "fruit": "Y" }} ]
}
}
在基巴纳语中使用:
GET index_name/_search
{
"query": {
# your search query here
}
}
可能这不是最好的解决方案,但希望对您有帮助。
在ES demo上尝试
要运行的示例代码:
GET kibana_sample_data_flights/_search
{
"query": {
"bool": {
"must": [
{"match": {
"OriginWeather": "Sunny"
}},
{"match": {
"Cancelled": false
}}
]
}
}
}