0

I am working on elastic search to fetch the record which contain string "bond"

{
  "query": {
    "match": {
      "name": "Bond"
    }
  }
}

but I am getting empty array as a output. Though multiple records are present containing string "bold" , but i am getting empty hits. (hits:[])

How to solve this issue?

I am using same query for another index and its working but for index named as "all_colleges", its not working. Its only returning the record when string is perfect match. i.e. "Bond" == "Bond"

4
  • Does this answer your question? elasticsearch query string containing / Commented Feb 14, 2022 at 9:35
  • nope, @KennetsuRinn Commented Feb 14, 2022 at 9:37
  • This reference may be helpful for you. Otherwise please show us the mappings of your ES. Commented Feb 14, 2022 at 9:45
  • @AdityaSonawane this is possible by allowing some fuzziness, you can check my answer below Commented Feb 14, 2022 at 10:23

2 Answers 2

1

You can try with fuzziness:

{
  "query": {
    "match": {
      "name": {
         "query": "Bond",
         "fuzziness": "AUTO"
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

6 Comments

its giving following output { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 0, "relation" : "eq" }, "max_score" : null, "hits" : [ ] } }
Can you share the mapping of the name field?
i dont have much knowledge, is there any way i can share my screen and you can help me to solve this issue
{ "properties": { "country": { "type": "keyword" }, "course_global_rank": { "type": "long" }, "course_name": { "type": "keyword" }, "global_rank": { "type": "long" }, "name": { "type": "keyword" }, "sub_course": { "type": "keyword" }, "sub_course_global_rank": { "type": "long" } } }
Ok, I see the problem, your name field is of type keyword (value is not analyzed), so the match query with fuzziness won't work here. You should change it to text instead
|
0

Actually there is many parameters you can add to get the results that you want in elastic search. Please check this link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

You can try this one

{
    "query": {
        "match": {
            "name": {
                "query": "Bond",
                "fuzziness": "AUTO"
             }
         }
     }
}

`

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.