Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k 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 (44.3k 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

        }

    }

}

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Jul 18, 2019 in AWS by yuvraj (19.1k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...