Matching search for a document that a user has access to.

0

I have two indices:

  • The docs index containing documents and
  • The permissions index, in which each document is a (doc_id, user_id) pair specifying that the user user_id has access to the document doc_id stored in the docs index.

Here are the definitions of the document classes for the two indices:

class MyDoc(Document):
    id = Text()
    date = Text()
    title = Text()

    def save(self, ** kwargs):
        return super(MyDoc, self).save(** kwargs)

class Permission(Document):
    doc_id = Text()
    user_id = Text()
    
    def save(self, ** kwargs):
        return super(Permission, self).save(** kwargs)

I am struggling with creating a query searching for a document to which a particular user has access. Here is what I have:

def search_user_doc(
    client, docs_index_name, permissions_index_name, user_id, title):
    response = client.search(
        index=docs_index_name, 
        body={
            "query": {
                "bool": {
                    "must": [
                        {
                            "match": {
                                "title": title
                            }
                        },
                        {
                            "join": {
                                "indices": permissions_index_name,
                                "on": ["doc_id", "id"],
                                "request": {
                                    "term": {
                                        "user_id": user_id
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    )
    print(response)

I get the error:

opensearchpy.exceptions.RequestError: RequestError(400, 'x_content_parse_exception', 'unknown query [join]').

I understand that this message is saying that there is no join query in OpenSearch. How can I fix this query?

P.S. The question is now posted in StackOverflow as well.

已提问 10 个月前78 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容