1

Why can't I get the same result in the second query as in the third one? What am I doing wrong?

  1. I make this query:
{
  "size": 20,
  "track_total_hits": false,
  "_source": [
    "title"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "63 ",
            "default_field": "title",
            "type": "phrase_prefix"
          }
        }
      ]
    }
  }
}

and got this result:

{
  "hits": {
    "max_score": 13.483224,
    "hits": [
      {
        "_index": "products_2022_11_3_17_30_44_56920",
        "_type": "_doc",
        "_id": "19637",
        "_score": 13.483224,
        "_source": {
          "title": "Заднее стекло 6302BGNE"
        }
      }
    ]
  }
}
  1. all right, after this I am typing one more character:

"query": "63 2"

and got empty result:

"hits" : {
    "max_score" : null,
    "hits" : [ ]
  }
}
  1. then I am adding one more character again:

"query": "63 21"

and got not empty result again:

{
  "hits": [
    {
      "_index": "products_2022_11_3_17_30_44_56920",
      "_type": "_doc",
      "_id": "105863",
      "_score": 440.54578,
      "_source": {
        "title": "Лампа накаливания 63 21 0 151 620 BMW"
      }
    }
  ]
}

Index mapping:

"title": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

GET products/_settings

{
  "products_2022_11_7_8_57_7_118045" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "products_2022_11_7_8_57_7_118045",
        "creation_date" : "1667800627119",
        "number_of_replicas" : "0",
        "uuid" : "GV6-5tzQQPavncFUcvq9NA",
        "version" : {
          "created" : "7170299"
        }
      }
    }
  }
}

1 Answer 1

1

Looks like you are using the some analyzer on your title field, that is creating tokens in search a way it doesn't match your search term.

I used the standard analyzer for title field and index the sample documents shown by you and its giving me results in all three queries. as shown below:

{
    "size": 20,
    "track_total_hits": true,
    "_source": [
        "title"
    ],
    "query": {
        "bool": {
            "must": [
                {
                    "query_string": {
                        "query": "63 2",
                        "default_field": "title",
                        "type": "phrase_prefix"
                    }
                }
            ]
        }
    }
}

Search Result

 "hits": [
            {
                "_index": "74308224",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.1689311,
                "_source": {
                    "title": "Лампа накаливания 63 21 0 151 620 BMW"
                }
            }
        ]

Giving your index mapping and settings would be helpful to identify why its not giving the expected result.

Sign up to request clarification or add additional context in comments.

8 Comments

Append an index mapping for titile field in my question. Notging special
@Slad very weird, are you using different default analyzer in your index?? can you provide the output of GET your-index/_settings API output on your index?
Added output in the question
@Slad can you also add GET _cluster/settings?include_defaults ?
Output is too big, so you can see here: codebeautify.org/online-json-editor/y22aa2c17
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.