英文:
using index like blacklist when searching on other index on Elasticsearch
问题
我正在使用Elasticsearch创建一个用户系统。
我想从名为'Users'的索引中获取所有用户的数据,并排除在名为'BannedUsers'的索引中列出的用户。
在SQL查询中,它看起来像这样:SELECT * FROM [Users] WHERE [name] NOT IN (SELECT [name] FROM [BannedUsers])。
在搜索另一个索引时,是否有一种方法可以将特定索引用作黑名单?
我想通过单个QueryDSL请求完成所有操作。
索引映射。
POST Users
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      }
    }
  }
}
POST BannedUsers
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      }
    }
  }
}
英文:
I am creating a user system using Elasticsearch.
I want to fetch data for all users from an index called 'Users' and exclude users whose names are listed in an index called 'BannedUsers'.
In a SQL query, it would look like this: SELECT * FROM [Users] WHERE [name] NOT IN (SELECT [name] FROM [BannedUsers]).
Is there any way to use a specific index as a blacklist when searching against another index?
I'd like to do everything with a single QueryDSL request.
indecs mapping.
POST Users
{
 "mappings": {
    "properties": {
      "name":{
         "type":"text"
    }
  }
}
POST BannedUsers
{
 "mappings": {
    "properties": {
      "name":{
         "type":"text"
    }
  }
}
答案1
得分: 1
你可以使用丰富策略并筛选数据。基本上,Users索引中的每个文档在丰富后都会有一个字段,像这样:is_banned: true,查询将如下所示:
GET users/_search
{
  "query": {
    "term": {
      "is_banned": false
    }
  }
}
英文:
You can use the enrichment policy and filter the data. Basically, each document in Users index will have a field after the enrichment like is_banned: true and the query will look like the following:
GET users/_search
{
  "query": {
    "term": {
      "is_banned": false
    }
  }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论