3

i want to perform both exact match and partial match. for example, "Alize", so if i type "Ali" it should return the result of "Alize" as well. for this case i only can return the result if i type exact word "Alize".

POST /ecommerce/_search
'{
  "query": {
      "multi_match": {
        "fields": [
          "name"
        ],
        "operator": "AND",
        "query": "Ali*"
      }
    },
    "size": 20,
    "stored_fields": [
      "uid",
      "_source"
    ]
}`
Christian Häckh
  • 512
  • 6
  • 11
kavi
  • 147
  • 2
  • 4
  • 14

2 Answers2

7

You can use querystring query as following

"query": {
    "query_string": {
        "query": "Ali*",
        "fields": ["name"]
    }
}

Or use wildcard

"query": {
    "filtered": {
          "filter": {
            "bool": {
              "must": [
                {"query": {"wildcard": {"name": {"value": "Ali*"}}}},
              ]
            }
        }
    }
}

Wildcard document

Mohammad Akbari
  • 4,486
  • 6
  • 43
  • 74
0

This solutions work perfectly for django_elasticsearch_dsl

search_keyword = search_keyword + "*"  
query = document_class.search().query(
        {
           "query_string": {
           "query": search_keyword,
           "fields": ["name", "code"]
           }
        }
sharif_42
  • 511
  • 4
  • 11