0 votes
1 view
in AWS by (18.2k points)

I'm facing some challenges with Elastic Search. I want to query for by some text and then filter based on a category. I followed the Elastic Search 6.3 Documentation for Queries but my response for ES is always empty. I know for a fact that I have at least one entry that should match the request. Below I have posted my query to Elastic Search and the entry that I know is present in my Elastic Search index. Any help is very much appreciated.

Query

{

    "from": 0,

    "size": 300,

    "query": {

      "bool": {

        "filter": {

          "term": {"category": "Soups"}

        },

        "should": [

          {"term": {"instructions": "Matt"}},

          {"term": {"introduction": "Matt"}},

          {"term": {"recipe_name": "Matt"}},

        ],

        "minimum_should_match": 1,

        "boost": 1.0

      }

    }

  }

Record Present in Elastic Search

        {

            "_index": "recipes",

            "_type": "_doc",

            "_id": "QMCScWoBkkkjW61rD81v",

            "_score": 0.2876821,

            "_source": {

                "calories": 124,

                "category": "Soups",

                "cook_time": {

                    "hour": "2",

                    "min": "4"

                },

                "cooking_temp": "375",

                "cooking_temp_units": "°F",

                "creator_username": "virtualprodigy",

                "ingredients": [

                    {

                        "majorQuantity": "1 ",

                        "measuring_units": "teaspoon",

                        "minorQuantity": " ",

                        "name": "mett"

                    }

                ],

                "instructions": "instructions",

                "introduction": "intro",

                "prep_time": {

                    "hour": "1",

                    "min": "2"

                },

                "recipe_name": "Matt Test",

                "servings": 1

            }

        }

1 Answer

0 votes
by (42.4k points)

Using a standard analyser will cause this problem. This means they are split into tokens and also lowercased. So, even if it is the same, they are case sensitive and would not match. So, the fix would be to change the tern queries into match queries. Eg:

{

    "from": 0,

    "size": 300,

    "query": {

        "bool": {

            "filter": {

                "match": {

                    "category": "Cakes"

                }

            },

            "should": [

                {"match": {"instructions": "Xxx"}},

                {"match": {"introduction": "Xxx"}},

                {"match": {"recipe_name": "Xxx"}}

            ],

            "minimum_should_match": 1,

            "boost": 1.0

        }

    }

}

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...