我使用Elasticsearch 2.4,我试图让一个行为像下面的SQL语句的查询:如何在过滤查询使用或与Elasticsearch 2.X
SELECT * FROM countries WHERE continent='Europe' and (country='Andorra' OR cities in ['Madrid'])
在Elasticsearch 1.5我得到它的工作使用以下查询:
{
"query": {
"filtered": {
"filter": {
"term": {
"continent": "Europe"
}
},
"query": {
"bool": {
"should": [
{
"nested": {
"path": "cities",
"query": {
"match": {
"cities.name": "Madrid"
}
}
}
},
{
"match": {
"country": "Andorra"
}
}
]
}
}
}
}
}
但是好像在2.x版的“过滤” has been deprecated帕拉姆。我试图使用新的方法使用过滤器来构建查询,但是它没有正确找到嵌套值。这是结果查询:
{
"query": {
"bool": {
"filter": [
{
"term": {
"continent": "Europe"
}
}
],
"should": [
{
"nested": {
"path": "cities",
"query": {
"match": {
"cities.name": "Madrid"
}
}
}
},
{
"match": {
"country": "Andorra"
}
}
]
}
}
}
这是我试图找回数据:
{
"_index":"countries",
"_type":"item",
"_id":"123",
"_version":1,
"found":true,
"_source":{
"country": "Spain",
"cities": [
{
"id_city": 2133,
"name": "Madrid"
},
{
"id_city": 8382,
"name": "Barcelona"
}
]
}
}
是否有人知道正确的方式来实现这一目标?
不,它没有。但无论如何,使用“必须”它不会有**或**的行为。我需要它匹配,如果它是某个国家或它是某个城市。 – Ander
你可以尝试用一个应该替换的“必须”吗?更新了答案。 – jay