2

I am currently working on trying out the Sitecore GraphQL Query where I just get all the items of a specific location in the Sitecore Tree. However, I may need to filter the item results based on a particular Field Value. Is it possible to do this on the GraphQL in Connected mode?

1

2 Answers 2

6

You can use an index search and filter whatever, Use somethings like this:

{
  search(
    fieldsEqual:[{name:"title", value:"Sit*" }] rootItem:"/sitecore/content"
        ) {
    results {
      items {
        item {
          id
          name
          path
          url
          field(name  : "title") {
           title: value
          }
        }
      }
      totalCount
    }
  }
}

This is searching, filtering on Title field in the tree below rootItem. For only searching in a specific location you can filter on parent id. somethings like this:

fieldsEqual:[{name:"title", value:"Sit*"} ,{name:"_parent",value:"0de95ae441ab4d019eb067441b7c2450"}]

8
  • How can i execute the same query in Sitecore xGraph browser? @Jan Bluemink
    – Hussain
    Commented Feb 20, 2019 at 11:03
  • This Query works also in Sitecore Experience Graph Browser go to /sitecore/api/graph/items/web/ui or the endpoint you have setup. Commented Feb 20, 2019 at 13:08
  • Cannot query field \"search\" on type \"Query\". error showing up after executing the query. @Jan Bluemink
    – Hussain
    Commented Feb 21, 2019 at 12:12
  • on /sitecore/api/graph/items/master/schema (url depend on your endpoint) you can see the schema.. and there should be a line: type Query { item(path: String, language: String, version: Int): Item sites(name: String = "", current: Boolean = false, includeSystemSites: Boolean = false): [SiteGraphType] templates(path: String): [ItemTemplate] search(first: Int, after: String = 0, rootItem: String, keyword: String, language: String, latestVersion: Boolean = true, index: String, fieldsEqual: [ItemSearchFieldQuery], facetOn: [String!]): ContentSearchResults } Commented Feb 21, 2019 at 12:26
  • 1
    you can found the search think in the \App_Config\Sitecore\Services.GraphQL\Sitecore.Services.GraphQL.Content.config in the <systemContent> .. <queries hint="raw:AddQuery"> ... <query name="search" type="Sitecore.Services.GraphQL.Content.Queries.SearchQuery, Sitecore.Services.GraphQL.Content" /> Commented Feb 21, 2019 at 15:46
1

Sitecore GraphQL Search Query - fieldsEqual parameter and it’s explicit usage.

In this query:

We utilize the fieldsEqual parameter to specify criteria for filtering search results based on the equality of field values. Two conditions are set: one for the “subtitle” field with the value “praveen” and another for the “description” field with the value “sharma”. The rootItem parameter defines the starting point of the search within the Sitecore content tree, limiting the search scope to the specified node.


    {
      search(
        fieldsEqual:[
          {name:"subtitle", value:"praveen" }
          {name:"description", value:"sharma" }
        
        ] 
        
        rootItem:"/sitecore/content/Home/MyProject/Home"
            ) {
        results {
          items {
            item {
              id
              name
              path
              url
             FirstName: field(name  : "subtitle") {
               value
              }
             LastName: field(name  : "description") {
               value
              }
            }
          }
          totalCount
        }
      }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.