0

My document schema is as follows.

Post

Id
Title
Body
Privacy -> Values can only be ["Me", "Anyone", "Team"]
UserId

What I want to do is retrieve all documents, but exclude documents where

Privacy = "Me" 
and 
UserId != "My-User-Id"

The SQL equivalent code is

SELECT * from Posts
WHERE (Privacy = "Anyone" OR Privacy = "Team")
OR (Visibility = "Me" AND UserId = 'My-User-Id')

I want to know how I can convert that SQL to the Elastic Search equivalent. Thanks, any help would be appreciated.

Coder Guy
  • 185
  • 5
  • 12
  • I am not sure if I understand. You already know what do you want to search and already have an equivalent SQL query, but what is the specific problem that you found? – Hernán Alarcón Jan 22 '21 at 23:09
  • @HernánAlarcón Ah sorry for the confusion. I want to convert that SQL query to the Elastic Search equivalent. – Coder Guy Jan 22 '21 at 23:10
  • Can't you use [SQL access](https://www.elastic.co/guide/en/elasticsearch/reference/current/xpack-sql.html)? It allows you to use SQL to query Elasticsearch indices. It even has a translate API to convert SQL queries into native Elasticsearch queries. – Hernán Alarcón Jan 22 '21 at 23:15
  • @HernánAlarcón I didn't even know that was a thing. I tried it just now and I got it to work. Thank you so much, you're a life saver. – Coder Guy Jan 23 '21 at 00:40

0 Answers0