Forum Discussion

anmi's avatar
anmi
Adept
2 years ago

json query syntax matches AND OR

Hello,

I cannot find the full json query syntax documentation here. Thats wha I'm asking in this post:

How does a json based query look like for AND matches in body text. I want to query all posts containing term1 AND term2 in their body.

 

My query currently is this. How do I add the term2?

[
{
"messages":{
"fields":[
"id",
"subject",
"search_snippet",
"body",
"cover_image.view_href",
"teaser",
"view_href",
"author",
"conversation.last_post_time",
"replies.count(*)",
"kudos.sum(weight)",
"metrics.views",
"labels"
],
"constraints":[
{
"category.id":"DE",
"conversation.style":"tkb",
"body":{ "matches":"term1" },
"depth":0
}
],
"sorts": [
"post_time desc"
],
"limit":10,
"subQueries":{
"labels":{
"fields":[
"text",
"id"
]
}
}
}
}
]
  • Hi anmi,

    Could you please try the below format,

    [
    {
    "messages":{
    "fields":[
    "id",
    "subject",
    "search_snippet",
    "body",
    "cover_image.view_href",
    "teaser",
    "view_href",
    "author",
    "conversation.last_post_time",
    "replies.count(*)",
    "kudos.sum(weight)",
    "metrics.views",
    "labels"
    ],
    "constraints":[
    {
    "category.id":"DE",
    "conversation.style":"tkb",
    "body":{ "matches":"term1" },
    "depth":0
    },
    {
    "body":{ "matches":"term2" },
    "depth":0
    }
    ],
    "sorts": [
    "post_time desc"
    ],
    "limit":10,
    "subQueries":{
    "labels":{
    "fields":[
    "text",
    "id"
    ]
    }
    }
    }
    }
    ] 

    • Akenefick's avatar
      Akenefick
      Genius

      SyedSa I was really struggling with something very similar trying to match multiple labels with an AND logic with a JSON query. Easy to do with regular LiQL but could not get it to work with JSON. This worked great. Thanks!

  • SyedSa Does the second matches constraint need that 'depth': 0? If so, why?