Wildcards+fuzzy in one query

I'm new to Elasticsearch and have 2 Questions:
Q1)
The following query return this result(pic):
Query:

     {
       "query": {
         "query_string": {
     			"query": "china~"
     		}
       }
     }

Result:

{
  "took": 12,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 1.3862942,
    "hits": [
      {
        "_index": "demo",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.3862942,
        "_source": {
          "title": "Asia country: china",
          "description": "Country in asia called Japan, Country in asia called china",
          "created_at": "2021-05-09"
        }
      },
      {
        "_index": "demo",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.1090355,
        "_source": {
          "title": "Asia country: chnia",
          "description": "Country in asia called Korea",
          "created_at": "2021-05-09"
        }
      },
      {
        "_index": "demo",
        "_type": "_doc",
        "_id": "3",
        "_score": 0.79423964,
        "_source": {
          "title": "Asia country: Japan",
          "description": "Country in asia called Japan but china is the big country ",
          "created_at": "2021-05-06"
        }
      }
    ]
  }
}

Why the score of doc with id:2 is greater than the score of doc with id:3 ?
in doc with id:2 we have chnia
in doc with id:3 we have china

Q2)
Can i make a Wildcards+fuzzy query for best result may something like this:

     {
       "query": {
         "query_string": {
     			"query": "*chin* OR chin~"
     		}
       }
     }

This query return docs that have this words : china(Wildcards), chni (fuzzy) but not return docs that have word: chnia

Welcome!

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with </> icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

It would be great if you could update your post to solve this.

About Q1, it's because of the length of the text. The shorter the text is, the higher the score is.

Q2: you should use bool queries with should clauses.

I wrote some queries like this in:

HTH

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.