如何从Amplify-AppSync-ElasticSearch-DynamoDB Stack中获取附近看不见的文档? [英] How to get unseen, nearby documents from a Amplify - AppSync - ElasticSearch - DynamoDB Stack?

查看:93
本文介绍了如何从Amplify-AppSync-ElasticSearch-DynamoDB Stack中获取附近看不见的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
使用AWS的Amplify.js。
一个Tinder类似的应用程序。
在这里您可以找到附近的工作。
这些可能只能看到一次。
我们应该保存用户喜欢和不喜欢的内容。

Problem: Use Amplify.js from AWS. A Tinder similar app. Here you can find jobs close by. These may only be seen once. We should save what the user likes and dislikes.

我已经管理的内容:

我有这个方案:


type Query {
  nearbyJobs(location: LocationInput!, km: Int): ModelJobConnection
}


type User @model {
  id: ID!
  name: String
  interacts: [Jobinteract] @connection(name: "interactsuser")
  createdAt: String
  updatedAt: String
}


type Job @model @searchable { 
  id: ID!
  name: String
  location: Location
  is_swiped_by: AWSJSON
  interacts: [Jobinteract] @connection(name: "interactjob")
  createdAt: String
  updatedAt: String
}

通过@searchable我已经建立了与ElasticSearch。因为这似乎是寻找附近工作的唯一方法。

With @searchable I have established the connection to ElasticSearch. Since this seems to be the only way to search for jobs nearby.

现在变得棘手。

此刻,我在以下字段中保存:is_seen_from_user所有已看到此工作的用户ID。由于到目前为止大约有1000位用户,所以可以。

At the moment I save in the field: is_seen_from_user all users id´s who have already seen this job. Since there were about 1000 users so far, that was ok.

这是我的查询:

"body": {
        "size": 30,
        "sort": [
          {
            "createdAt": {
              "order": "desc"
            }
          }
        ],
        "query": {
          "bool": {
            "must": [
              {
                "range": {
                  "createdAt": {
                    "gte": "now-30d/d"
                  }
                }
              }
            ],
            "must_not": {
              "match_phrase": {
                "is_swiped_by.user": "$ctx.identity.sub"
              }
            },
            "filter": {
              "geo_distance": {
                 "distance" : "${distance}km",
                 "location" : $util.toJson($ctx.args.location)
              }
            }
          }
        }

is_swiped_by.user
因此,我查看了该数组以查看用户是否在那儿。
如果可以的话-跳过。

is_swiped_by.user So I looked into the array to see if the user was there. if yes - skip.

但是现在我有一个问题,那就是可以有更多的用户。

But now I rather have the problem that there can be more users.

这意味着,我无法再将其保存到字段中。
可能必须有一个新表。

This means, I can't save it into a field anymore. There would probably have to be a new table.

type Jobinteract @model {
  id: ID!
  user: User! @connection(name: "interactsuser")
  job: Job! @connection(name: "interactjob")
  decision: Int
  createdAt: String
  updatedAt: String
}

现在的问题是。如果我现在有桌子(Jobinteract)。我应该也将其设置为@searchable吗?

The question now is. If I have the table (Jobinteract) now. Should I make it @searchable too?

然后,我在ElasticSearch中也有数据。但是我怎么能把他们聚在一起呢?
然后是来自不同索引的数据。

Then I also have the data in ElasticSearch. But how can I bring them together? It is then data from different indexes.

我在ES中读过hasChild。但是,如果正确的方法,不知道该如何工作?!

I read hasChild in ES. But don't understand exactly how this should work, if it's the right way?!

我目前也在测试我是否可以通过lambda访问ES,所以我只想打电话给附近的所有工作,然后自己比较一下。
但这可能不是最佳选择。
从Elasticsearch附近获得100份工作,将其与下表进行比较。如果还剩下50个,请将其发送到前端,否则,请再获取100个。
用户喜欢的越多,该调用就会越久。

i'm also currently testing whether i can get access to ES via a lambda, so i'd just call up all the jobs nearby and compare them myself. But that's probably not the best option. Get 100 jobs from nearby from Elasticsearch, compare it to the table below. If there are 50 left, send them to the frontend, if not, get 100 again. The more the user liked, the longer this call would go.

推荐答案

@searchable指令当前不支持自定义ElasticSearch映射开箱即用,因此您将需要为ElasticSearch集群执行一些自定义设置。您应该能够使用诸如hasChild之类的联接查询来查找同一索引中没有关联的子记录的所有位置,这些位置指示用户之前已经与作业进行了交互。

The @searchable directive does not currently support custom ElasticSearch mappings out of the box so you will need to perform some custom setup for your ElasticSearch cluster. You should be able to use joining queries such as hasChild to find all locations where there is no associated child record in the same index that indicates the user has interacted with the job before.

撰写本文时,@searchable指令将不同的@models存储在单独的索引中,因此您将需要编写一个自定义解析程序,以将 Interaction子记录放入指定用户与作业进行交互的相同索引中,然后您将需要更新ES索引映射,以便它使用联接数据类型,以便可以使用hasChild查询。参见 https://www.elastic.co/guide /en/elasticsearch/reference/current/parent-join.html 了解更多信息。

As of writing, the @searchable directive stores different @models in separate indexes so you will need to write a custom resolver that puts the "Interaction" child record in the same index that specifies when a user has interacted with a job and then you will need to update the ES index mapping such that it uses a join data type so you can use the hasChild query. See https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html for more information.

这篇关于如何从Amplify-AppSync-ElasticSearch-DynamoDB Stack中获取附近看不见的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆