aws / aws/aws-appsync-community

How to use "OR" in GraphQL query is not working as I would expect in AppSync Console

Open
#144 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

I am using AWS Amplify with DynamoDB and Elastisearch and my expectations for how to use the "Or" in graphQL query seem to be wrong but I cant figure out how to get it right and any advice would be appreciated since I am fairly sure that this is possible.

My expectation is that I could use an OR in a query in a similar fashion to how it is used in SQL. My dataset is a set of NewsArticles that have a title and a description that are both strings. What I want to be able to do (for this sample) is show all the articles that have the word "orange" in _either_ the title or the description.

To show that this data exists I am starting with the query below (that only filters on the title)
```
query searchNews {
searchNewsArticles(filter: {newstitle: {matchPhrase: "orange"}}) {
items {
description
newstitle
}
total
}
}

```

This returns the following data (as expected):

```
{
"data": {
"searchNewsArticles": {
"items": [
{
"description": "ALBANY, N.Y. (NEWS10)- The first shipments of COVID-19 vaccines from Pfizer and Moderna have been sent to local area hospitals with some employees getting vaccinated over the past week. Frontline w…",
"newstitle": "DOH: Orange County health care provider may have fraudulently obtained COVID-19 vaccine"
},
{
"description": "Gulf Shores, Orange Beach and the area of Fort Morgan are closed to visitors for at least 10 days.",
"newstitle": "Gulf Shores, Orange Beach closed to visitors for at least 10 days"
},
{
"description": "Sheriff Don Barnes, Orange County, Calif., reacts to judge's order reducing prison population amid coronavirus pandemic.",
"newstitle": "Orange County sheriff refuses to release 1,800 inmates after judge's order: 'Serious threat' to community"
},
{
"description": "The Associated Press has called the 39th Congressional District race for Republican Young Kim, marking the second race in the county in which the GOP took back a district Democrats had flipped in 2018. ",
"newstitle": "Young Kim defeats Gil Cisneros in another victory for Republicans in Orange County"
},
{
"description": "The Silverado Fire and the Blue Ridge Fire in Orange County forced more than 90,000 evacuations Monday.",
"newstitle": "Orange County besieged with blazes; Northern California largely spared | CalMatters"
},
{
"description": "Restaurants, movie theaters and places of worship can resume indoor operations with modifications after the county moved from the purple tier to the red tier in California's coronavirus guidelines.",
"newstitle": "Orange County shows progress in COVID-19 fight as businesses are allowed to reopen indoor operations"
},
{
"description": "Placer County progresses to orange COVID-19 tier",
"newstitle": "Placer County progresses to orange COVID-19 tier"
},
{
"description": "Letters to the Editor.",
"newstitle": "Mailbag: Orange County put politics over the sound medical advice of its health officer"
},
{
"description": "undefined",
"newstitle": "Orange County school Board of Education wants schools to reopen, no social distancing: report"
},
{
"description": "Just when Bay Area residents thought the world outside couldn't get even stranger, the sky early Wednesday glowed a bright pumpkin orange you'd expect to see on Mars.
With wildfire smoke high aloft in the atmosphere, the sky was an eerie yellow color on Tuesday, but today with more sooty air traveling above the region, the color turned an even stranger, richer hue.",
"newstitle": "Thick wildfire smoke blocks sun, turns Bay Area sky orange"
},
{
"description": "National Weather Service meteorologist Steve Anderson said an increase an on-shore winds as the weekend approaches “won’t be enough to blow this smoke out of the area, but it should be …",
"newstitle": "Orange glow turns dark and gray as Bay Area air quality worsens"
},
{
"description": "The increase has prompted hospitals in the region to begin to prepare for a surge of sick patients, according to the director of the Orange County Health Care Agency.",
"newstitle": "Coronavirus hospitalizations jump 97% in Orange County in less than a month"
},
{
"description": "'This does not diminish the importance of face coverings,' Orange County's new health director says in loosening COVID-19 pandemic requirements. ",
"newstitle": "Orange County rescinds coronavirus mask mandate amid pushback, resignation"
},
{
"description": "Republican candidates lead two of California's most competitive races in Orange County, taking back lost ground from 2018. The candidates, Young Kim and Michelle Steel, could be the first Korean American women in Congress. ",
"newstitle": "Republicans may take back two congressional seats in key Orange County races"
},
{
"description": "Power company Southern California Edison told state regulators that its equipment may have ignited one of a pair of fast-moving wildfires in Orange County, Calif., that have prompted evacuation orders for 80,000 people.",
"newstitle": "SoCal Edison says it may have caused Orange County wildfire"
},
{
"description": "On the 27th anniversary of a destructive wildfire in Laguna Beach, the author ponders the lessons she's learned about fire and safety since then.",
"newstitle": "Opinion: Orange County fires spur memories of the 1993 Laguna Canyon blaze — and the lessons learned since "
},
{
"description": "Wildfire smoke turned California and Oregon skies orange. Inside that smoke was alchemy—the chemistry and physics of molecules and wavelengths.",
"newstitle": "Those Orange Bay Area Skies and the Science of Light"
},
{
"description": "California braced for a new round of fires as Santa Ana winds roar. Firefighters turned out in force to battle a blaze in the Silverado Canyon area.",
"newstitle": "Two firefighters badly burned as two wildfires in California's Orange County prompt evacuation of 71,000 homes"
},
{
"description": "As campuses begin to reopen, teachers watch anxiously and some are raising concerns publicly, including Orange County teachers who led a protest and signed a petition.",
"newstitle": " 'No safety, no learning': Many Orange County teachers protest reopening schools"
},
{
"description": "What were being described as ",
"newstitle": "Viral Photos Showing Ominous Orange Skies in San Francisco Maybe Result of California Wildfires"
},
{
"description": "Orange County joins San Diego as the only counties in Southern California not having “widespread risk” under the state’s COVID-19 monitoring system.",
"newstitle": "As COVID-19 risk dips, Orange County gets OK to reopen indoor restaurants, movie theaters "
},
{
"description": "An estimated 90,000 people in southern California have been ordered to evacuate from their homes as two wildfires in Orange County blaze out of control.",
"newstitle": "California authorities evacuate 90,000 people in Orange County"
},
{
"description": "San Francisco is no longer the only Bay Area county in the orange.",
"newstitle": "2 more Bay Area counties jump from red to orange tier in COVID-19 reopening plan"
},
{
"description": "From San Francisco to Yosemite, social media was filled with images of ominous red and orange skies as smoke from a variety of fires blocked the sun.",
"newstitle": "Deep orange skies, 'snowing' ash as fire smoke swamps Bay Area"
},
{
"description": "A cash-strapped President Trump stopped in California to raise money 16 days before election day, appearing at a high-dollar Newport Beach fundraiser.",
"newstitle": "The Beach Boys, tony Lido Isle, $150,000 tickets: A peek inside Trump's Orange County fundraiser"
},
{
"description": "Public health experts say wearing a mask can prevent the spread of COVID-19, but in Orange County many are still skeptical.",
"newstitle": "Many in Orange County resist masks even as coronavirus cases soar"
},
{
"description": "Orange County argue that its coronavirus conditions are not as bad as in the hot zones and maintain the state should not treat them like L.A. County.",
"newstitle": "'It's devastating.' Orange County merchants, officials say COVID order shouldn't lump them in with L.A."
},
{
"description": "The California Supreme Court is considering whether Gov. Gavin Newsom is violating the Constitution by forbidding in-classroom instruction for K-12 schools during the pandemic.",
"newstitle": "Orange County wants justices to reopen schools statewide. Experts say it's a long shot"
},
{
"description": "A U.S. Postal Service carrier has been accused of throwing away 1,875 pieces of mail, including election ballots and campaign flyers.",
"newstitle": "West Orange Election Mail Found In North Arlington Dumpster: Feds"
},
{
"description": "undefined",
"newstitle": "2 firefighters ‘gravely injured’ as wildfires rage in Orange County: report"
},
{
"description": "It seemed like fires popped up everywhere in Southern California on Tuesday: Topanga, Glendale, Acton, Riverside, San Diego. Most of them were quickly extinguished, but the each one likely rattled …",
"newstitle": "Multiple New Fires Spark Across Southern California As Orange County Blaze Spreads Freely, Overwhelming Local Resources; 5 Firefighters Injured; Power Lines Again Suspect In Ignition"
},
{
"description": "California Gov. Gavin Newsom (D) on Friday announced that some schools in the state will remain online-only in the fall rather than reopening to in-person classes.",
"newstitle": "California governor says Orange County can't reopen schools days after vote to reopen"
},
{
"description": "What is happening now is astonishingly worse than any previous fire season. We are in a new kind of era",
"newstitle": "California's dark, orange sky is the most unnerving sight I've ever woken up to | Rebecca Solnit"
},
{
"description": "undefined",
"newstitle": "Southern California Edison says its equipment may have caused Orange County fire"
},
{
"description": "UPDATE (9/16/20 3:08 AM) — The Police Department and Fire Departments were making water rescues in South Baldwin County, however they had to pull back for now due to the severity of Sally. Th…",
"newstitle": "Dangerous conditions reported in Gulf Shores, Orange Beach as Sally rolls ashore"
},
{
"description": "Although the twin fires were burning about 30 miles away, the strong winds that drove the blazes through brushy Orange County hills also carried smoke to Long Beach, prompting authorities to warn residents to stay inside as much as possible.",
"newstitle": "Fierce winds drive wildfires through Orange County, prompt smoke warning in Long Beach • Long Beach Post News"
},
{
"description": "As coronavirus cases continue to rise in California, Orange County remains defiant against the state’s orders to wear a mask, raising questions as to how far officials are willing to go to enforce the measure.",
"newstitle": "Orange County remains battleground against California's coronavirus mask orders"
},
{
"description": "An unprecedented eerie orange glow blanketed the Bay Area on Wednesday as northern California wildfires burned.",
"newstitle": "Photos: Skies turn orange on Bay Area’s darkest day"
},
{
"description": "Winds had already dropped enough that 14 water-dropping helicopters could go to work again",
"newstitle": "Firefighters hope for a break in the wind as 2 wildfires burn in California's Orange County as 90,000 remain evacuated"
},
{
"description": "Orange County Board of Education panel supports reopening schools in the fall but does not recommend increased social distancing or face coverings.",
"newstitle": "Orange County votes to reopen schools without masks or increased social distancing"
},
{
"description": "The cash-strapped president comes to deep blue California to raise money 16 days before election day, heading to Newport Beach for a high-dollar fundraiser.",
"newstitle": "The Beach Boys, tony Lido Isle, $150,000 tickets: A peek inside Trump's Orange County fundraiser"
},
{
"description": "(WIVB)– New York State Health Commissioner Dr. Howard Zucker announced today that Parcare Community Health Network in Orange County, New York may have fraudulently obtained the COVID-19 vacci…",
"newstitle": "NYSDOH: Healthcare provider in Orange County, NY may have fraudulently obtained COVID-19 vaccine"
},
{
"description": "The state says Parcare Community Health Network was not supposed to receive COVID-19 vaccine and is now diverting it to whoever wants it.",
"newstitle": "New York investigating reports of vaccine fraud in Orange County"
},
{
"description": "Two major out-of-control wildfires in Southern California have spurred mass evacuations and left two firefighters critically injured as the region faces more dangerous fire weather conditions Tuesday. ",
"newstitle": "California wildfires force 100,000 from homes in Orange County, neighbors help fire crews"
}
],
"total": 44
}
}
}
```

as you can see there are multiple records that contain the word "orange" in both the title and the description text. My expectation however is that if I add and OR and ask for records that contain "orange" in the title OR the description I should still get at least these records returned, but when I add the OR I seem to get _less_ records returned (only records that have orange in both title and description).

Here is how my query looks with the additional OR:
```
query searchNews {
searchNewsArticles(filter: {newstitle: {matchPhrase: "orange"}, or: {description: {matchPhrase: "orange"}}}) {
items {
description
newstitle
}
total
}
}
```

This is the data that is returned from the second query with the OR which should return more records but in fact returns less:
```
{
"data": {
"searchNewsArticles": {
"items": [
{
"description": "Gulf Shores, Orange Beach and the area of Fort Morgan are closed to visitors for at least 10 days.",
"newstitle": "Gulf Shores, Orange Beach closed to visitors for at least 10 days"
},
{
"description": "Sheriff Don Barnes, Orange County, Calif., reacts to judge's order reducing prison population amid coronavirus pandemic.",
"newstitle": "Orange County sheriff refuses to release 1,800 inmates after judge's order: 'Serious threat' to community"
},
{
"description": "The Silverado Fire and the Blue Ridge Fire in Orange County forced more than 90,000 evacuations Monday.",
"newstitle": "Orange County besieged with blazes; Northern California largely spared | CalMatters"
},
{
"description": "Placer County progresses to orange COVID-19 tier",
"newstitle": "Placer County progresses to orange COVID-19 tier"
},
{
"description": "Just when Bay Area residents thought the world outside couldn't get even stranger, the sky early Wednesday glowed a bright pumpkin orange you'd expect to see on Mars.
With wildfire smoke high aloft in the atmosphere, the sky was an eerie yellow color on Tuesday, but today with more sooty air traveling above the region, the color turned an even stranger, richer hue.",
"newstitle": "Thick wildfire smoke blocks sun, turns Bay Area sky orange"
},
{
"description": "The increase has prompted hospitals in the region to begin to prepare for a surge of sick patients, according to the director of the Orange County Health Care Agency.",
"newstitle": "Coronavirus hospitalizations jump 97% in Orange County in less than a month"
},
{
"description": "'This does not diminish the importance of face coverings,' Orange County's new health director says in loosening COVID-19 pandemic requirements. ",
"newstitle": "Orange County rescinds coronavirus mask mandate amid pushback, resignation"
},
{
"description": "Republican candidates lead two of California's most competitive races in Orange County, taking back lost ground from 2018. The candidates, Young Kim and Michelle Steel, could be the first Korean American women in Congress. ",
"newstitle": "Republicans may take back two congressional seats in key Orange County races"
},
{
"description": "Power company Southern California Edison told state regulators that its equipment may have ignited one of a pair of fast-moving wildfires in Orange County, Calif., that have prompted evacuation orders for 80,000 people.",
"newstitle": "SoCal Edison says it may have caused Orange County wildfire"
},
{
"description": "Wildfire smoke turned California and Oregon skies orange. Inside that smoke was alchemy—the chemistry and physics of molecules and wavelengths.",
"newstitle": "Those Orange Bay Area Skies and the Science of Light"
},
{
"description": "As campuses begin to reopen, teachers watch anxiously and some are raising concerns publicly, including Orange County teachers who led a protest and signed a petition.",
"newstitle": " 'No safety, no learning': Many Orange County teachers protest reopening schools"
},
{
"description": "Orange County joins San Diego as the only counties in Southern California not having “widespread risk” under the state’s COVID-19 monitoring system.",
"newstitle": "As COVID-19 risk dips, Orange County gets OK to reopen indoor restaurants, movie theaters "
},
{
"description": "An estimated 90,000 people in southern California have been ordered to evacuate from their homes as two wildfires in Orange County blaze out of control.",
"newstitle": "California authorities evacuate 90,000 people in Orange County"
},
{
"description": "San Francisco is no longer the only Bay Area county in the orange.",
"newstitle": "2 more Bay Area counties jump from red to orange tier in COVID-19 reopening plan"
},
{
"description": "From San Francisco to Yosemite, social media was filled with images of ominous red and orange skies as smoke from a variety of fires blocked the sun.",
"newstitle": "Deep orange skies, 'snowing' ash as fire smoke swamps Bay Area"
},
{
"description": "Public health experts say wearing a mask can prevent the spread of COVID-19, but in Orange County many are still skeptical.",
"newstitle": "Many in Orange County resist masks even as coronavirus cases soar"
},
{
"description": "Orange County argue that its coronavirus conditions are not as bad as in the hot zones and maintain the state should not treat them like L.A. County.",
"newstitle": "'It's devastating.' Orange County merchants, officials say COVID order shouldn't lump them in with L.A."
},
{
"description": "Although the twin fires were burning about 30 miles away, the strong winds that drove the blazes through brushy Orange County hills also carried smoke to Long Beach, prompting authorities to warn residents to stay inside as much as possible.",
"newstitle": "Fierce winds drive wildfires through Orange County, prompt smoke warning in Long Beach • Long Beach Post News"
},
{
"description": "As coronavirus cases continue to rise in California, Orange County remains defiant against the state’s orders to wear a mask, raising questions as to how far officials are willing to go to enforce the measure.",
"newstitle": "Orange County remains battleground against California's coronavirus mask orders"
},
{
"description": "An unprecedented eerie orange glow blanketed the Bay Area on Wednesday as northern California wildfires burned.",
"newstitle": "Photos: Skies turn orange on Bay Area’s darkest day"
},
{
"description": "Orange County Board of Education panel supports reopening schools in the fall but does not recommend increased social distancing or face coverings.",
"newstitle": "Orange County votes to reopen schools without masks or increased social distancing"
},
{
"description": "(WIVB)– New York State Health Commissioner Dr. Howard Zucker announced today that Parcare Community Health Network in Orange County, New York may have fraudulently obtained the COVID-19 vacci…",
"newstitle": "NYSDOH: Healthcare provider in Orange County, NY may have fraudulently obtained COVID-19 vaccine"
}
],
"total": 22
}
}
}
```

The query seems to be doing an AND instead of an OR as it is returning less results and all seem to have "orange" in both title and the description. My expectation is that adding the OR to my second query would open up the filter and show more records not less. What am i missing? Thanks!

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the searchNewsArticles query in the AppSync Console using the filter shown in the issue, then read the AppSync GraphQL filter and Elasticsearch search documentation. Done means identifying a supported filter expression that returns articles when “orange” appears in either newstitle or description.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, elasticsearch, graphql
Domain
api, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.