【问题标题】:Elastic Search - OR filter with boolean and ids弹性搜索 - 使用布尔值和 id 进行或过滤
【发布时间】:2012-03-12 13:47:59
【问题描述】:

我正在尝试搜索项目,其中一些可能是私有的。

如果一个项目是私有的,只有项目所有者的朋友(数组 item.friends)可以看到这个项目。 如果它不是私人的,每个人都可以看到它。

所以我的逻辑是: 如果项目 not is_private (is_private=0) OR 用户 ID(在我的示例中为 4)在数组 item.friends 中,则用户可以看到该项目。

我仍然没有得到任何结果。现在每个项目都设置为is_private=1,所以我猜我的 ids 过滤器有问题。

有什么建议吗?

// ---- Mapping
{
    "item": {
        "properties": {
            "name": {
                "type": "string"
            },
            "description": {
                "type": "string"
            },
            "created": {
                "type": "date"
            },
            "location": {
                "properties": {
                    "location": {
                        "type": "geo_point"
                    }
                }
            },
            "is_proaccount": {
                "type": "integer"
            },
            "is_given_away": {
                "type": "integer"
            },
            "is_private": {
                "type": "integer"
            },
            "friends": {
                "type": "integer",
                "index_name": "friend"
            }
        }
    }
}

// ----- Example insert
{
    "name": "Test",
    "description": "Test",
    "created": "2012-02-20T12:21:30",
    "location": {
        "location": {
            "lat": "59.919914",
            "lon": "10.753414"
        }
    },
    "is_proaccount": "0",
    "is_given_away": "0",
    "is_private": 1,
    "friends": [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10
    ]
}

// -----  Query
{
    "from": 0,
    "size": 30,
    "filter": {
        "or": [
            {
                "bool": {
                    "must": [
                        {
                            "term": {
                                "is_private": 0
                            }
                        }
                    ]
                }
            },
            {
                "ids": {
                    "values": [
                        4
                    ],
                    "type": "friends"
                }
            }
        ]
    },
    "query": {
        "match_all": {}
    }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    “ids”过滤器可能并不像您认为的那样:它过滤 文档 ID(以及,可选地,文档类型)。

    见http://www.elasticsearch.org/guide/reference/query-dsl/ids-filter.html

    【讨论】:

    • 你说的完全正确!对于那个很抱歉。现在,有没有可以在我的“朋友”数组中搜索的过滤器?
    • 一个简单的术语过滤器应该可以做到。感谢您帮助我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多