1

Suppose I have the following document:

record 1:

{
  "name": "A Regular Book",
  "tags": [{ "name": "free-shipping" }, { "name": "summer-sale" }],
  "information": [
    { "key": "school_name", "value": "Berkley bobs", "country": "USA" },
    { "key": "school_name", "value": "Stanford summer", "country": "USA" },
    { "key": "id", "value": "1234", "country": "USA" },
    { "key": "id", "value": "2345", "country": "USA" }
  ]
}

record 2:

{
  "name": "A Regular Book 2",
  "tags": [{ "name": "free-shipping" }, { "name": "summer-sale" }],
  "information": [
    { "key": "school_name", "value": "Stanford summer", "country": "USA" },
    { "key": "school_name", "value": "Berkley bubbles", "country": "USA" },
    { "key": "id", "value": "1234", "country": "USA" },
    { "key": "id", "value": "2345", "country": "USA" }
  ]
}

And I am trying to do fuzzy search on one of the nested fields "key" how shall I approach it?

{
  "query": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "information.key": {
                                "value": "school_name",
                            }
                        }
                    },
                ]
            },
            "fuzzy": {
                "information.value": {
                    "value": variable_to_be_fuzzy_searched,
                }
            }
        }
}

How shall I do fuzzy search in such a way on the key field where key=school_name and it's value can be fuzzy search - variable_to_be_fuzzy_searched = Ber would return records 1&2 with this-> Berkley bobs, Berkley bubbles.

any hints will be appreciated :)

2
  • as far as I can understand your question, you need to get all those documents that have information.key= "school_name" and information.value beginning with Ber. Is this correct ?
    – ESCoder
    Jan 13 at 7:01
  • Yes you are right. Documents which have information.key = “school_name” and information.value can be fuzzy search field, not a wildcard though.
    – AstroNomad
    Jan 13 at 7:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.