Opensearch

https://localhost:4443/_dashboards/app/dev_tools#/console

AWS elasticsearch rip off

async function getUsersWithContactCountByPhoneNumberMap(
  ctx: Ctx,
  callerUserId: string,
  phoneNumbers: string[]
) {
  const response = await ctx.openSearchClient.search({
    index: process.env.OPENSEARCH_USER_CONTACT_V1_INDEX_NAME,
    body: {
      size: 0,
      query: {
        bool: {
          must: [
            {
              terms: {
                'phoneNumber.keyword': phoneNumbers,
              },
            },
          ],
          must_not: [
            {
              term: {
                'owner.keyword': callerUserId,
              },
            },
          ],
        },
      },
      aggs: {
        phoneNumbers: {
          terms: {
            field: 'phoneNumber.keyword',
            size: Math.min(phoneNumbers.length, MAX_ES_SIZE),
          },
          aggs: {
            uniqueOwnerCounts: { cardinality: { field: 'owner.keyword' } },
          },
        },
      },
    },
  });

  return response.body?.aggregations?.phoneNumbers?.buckets?.reduce(
    (acc, curr) => ({ ...acc, [curr.key]: curr.uniqueOwnerCounts.value }),
    {} as Record<string, number>
  );
}

Scripting

Go to https://localhost:4443/_dashboards/app/dev_tools#/console

  • Can do custom scoring/filters

Deving

Last updated