0

I try to update query of the component by using setQuery() prop. My data is structured like this.

{
    root : {
        category 1: {
            item 1 {...},
            item 2 {...},
        },
        category 2: {
            item 1 {...},
            item 2 {...},
        },
        ...    
    }
}

I need to get item 1 under the category 1. When user select item 1 I update query like this. But it doesn't work.

this.props.setQuery({
    "query": {
        "bool": {
        "must": [
            {
            "query_string": {
                "query": 'category 1 AND item 1',
                "fields": ["item", "category", "keywords"],
                "analyzer": "standard"

            }
            }
        ]
        }
    }
});

I try find out how to solve this using nested query. But I couldn't find any use full thing. Please give me any clue to achieve this.

Janaka Pushpakumara
  • 4,769
  • 5
  • 29
  • 34

1 Answers1

0

I found a solution for this.

this.props.setQuery({
        query: {
          bool: {
            must: [
              {
                terms: {
                  'parentName': ['category 1']
                },
              },
              {
                terms: {
                  'childName': 'item 1',
                },
              },
            ],
          },
        },
      });

I think this will helps to someone.

Janaka Pushpakumara
  • 4,769
  • 5
  • 29
  • 34