question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrectly convert nested query

See original GitHub issue
PUT index
{
  "mappings": {
    "my_case": {
      "properties": {
        "events": {
          "type": "nested" 
        }
      }
    }
  }
}

I made mapping structure like this. every row has more than two events data and would like to find one of events that matches poid and oid.

select name from my_case where (events.poid='A' and events.oid='B');

This is how I tried to query through sql4es, but It seems not results as I expected.

from sql4es
{
  "size": 200,
  "timeout": 10000,
  "post_filter": {
    "bool": {
      "must": [
        {
          "nested": {
            "query": {
              "term": {
                "events.poid": "A"
              }
            },
            "path": "events"
          }
        },
        {
          "nested": {
            "query": {
              "term": {
                "events.oid": "B"
              }
            },
            "path": "events"
          }
        }
      ]
    }
  }
}

It found every events that has poid is ‘A’ OR oid is ‘B’. How should I made query to find matching both condition?

This is what I want to make through sql4es

   .....
    "query": {
        "nested": {
           "path": "events",
           "filter": {
               "bool" : {
                    "must" : [
                        {"term" : { "events.poid" : "A"}},
                        {"term" : { "events.oid" : "B"}}
                    ]
               }
           }
        }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
corneverslootcommented, Apr 5, 2016

Thanks for your thorough explanation of the problem! I understand the issue and my guess right now is that it is a bug in the driver which I will have to verify. The last example in your post is exactly what it should be and ill look into it (might be a bit tricky to get it done though so will take some time)

0reactions
kdh6429commented, Apr 7, 2016

Everything are solved with kind explanation 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert a nested subquery into normal query - Stack Overflow
I have problem with following query where in which the nested query should be converted to normal query: select count(*) as count, ...
Read more >
how can I convert this SQL statement with nested IN clauses to ...
You can get this by changing each IN subquery into a join, and matching the columns in the join condition. SELECT Q.* FROM...
Read more >
how to convert nested query to join - Oracle Communities
I wrote a query, at first i find the name of the highest mountain,then find its provience and then list of mountains in...
Read more >
Avoid automatic convert nested queries to joins #27267 - GitHub
This is not converting nested query to joins. The subquery returns single scalar result and is placed directly into projection because a scalar ......
Read more >
Writing Subqueries in SQL | Advanced SQL - Mode Analytics
Subqueries (also known as inner queries or nested queries) are a tool for performing operations in multiple steps. For example, if you wanted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found