Reputation: 45
I've been handed a project from a coworker that resigned and without any documentation I'm finding it quite hard to grasp what's wrong with my ElasticSearch results.
If i search the word 'nik' on our e-commerce site i get 4 results:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 25.30471,
"hits" : [
{
"_index" : "elineutv415",
"_type" : "_doc",
"_id" : "100500102__sv",
"_score" : 25.30471,
"_source" : {
"IdDim1" : "",
"D22301" : "100500102",
"D22302" : "D850Nikon",
"IdLang" : "sv",
"D22311" : ""
}
},
{
"_index" : "elineutv415",
"_type" : "_doc",
"_id" : "100500103__sv",
"_score" : 25.30471,
"_source" : {
"IdDim1" : "",
"D22301" : "100500103",
"D22302" : "D850Nikon",
"IdLang" : "sv",
"D22311" : ""
}
},
{
"_index" : "elineutv415",
"_type" : "_doc",
"_id" : "100500100__sv",
"_score" : 24.19808,
"_source" : {
"IdDim1" : "",
"D22301" : "100500100",
"D22302" : "NikonD850",
"IdLang" : "sv",
"D22311" : ""
}
},
{
"_index" : "elineutv415",
"_type" : "_doc",
"_id" : "100500101__sv",
"_score" : 24.19808,
"_source" : {
"IdDim1" : "",
"D22301" : "100500101",
"D22302" : "NikonD850",
"IdLang" : "sv",
"D22311" : ""
}
}
]
}
}
However if I search 'D850' or '850' in otherwise the exact same query, I get no results. Even tho the searchstring is in the fields that I'm searching. Any ideas what I'm missing here?
Below is my query
{"size": 500, "query": { "bool": { "must": { "multi_match": { "query": "nik", "fields": ["D22302^3", "D22301^2", "D22311^1"]}},"filter": { "term":{ "IdLang.keyword": "sv"}}}}}
My mapping
{
"elineutv415": {
"mappings": {
"properties": {
"D22301": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"D22302": {
"type": "text",
"analyzer": "ngram_analyzer"
},
"D22311": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"IdDim1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"IdLang": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
Index settings
{
"elineutv415": {
"settings": {
"index": {
"max_ngram_diff": "11",
"number_of_shards": "1",
"provided_name": "elineutv415",
"creation_date": "1621850814863",
"analysis": {
"analyzer": {
"ngram_analyzer": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "ngram_tokenizer"
}
},
"tokenizer": {
"ngram_tokenizer": {
"token_chars": [
"letter",
"punctuation",
"symbol"
],
"min_gram": "3",
"type": "ngram",
"max_gram": "8"
}
}
},
"number_of_replicas": "1",
"uuid": "_DT9ytVSSwKPSWCOsFTp1Q",
"version": {
"created": "7030199"
}
}
}
}
}
Upvotes: 0
Views: 321
Reputation: 16172
You have set "max_gram":3
, due to which the maximum token length is set to 3. Due to this, there are no tokens generated for D850
OR 850
.
Adding a working example with index mapping, search query, and search result
Index Mapping:
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer",
"filter": "lowercase"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 8, // note this
"token_chars": [
"letter",
"digit"
]
}
}
},
"max_ngram_diff": 10
},
"mappings": {
"properties": {
"D22302": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
Index Data:
{
"IdDim1": "",
"D22301": "100500102",
"D22302": "D850Nikon",
"IdLang": "sv",
"D22311": ""
}
{
"IdDim1": "",
"D22301": "100500103",
"D22302": "D850Nikon",
"IdLang": "sv",
"D22311": ""
}
{
"IdDim1": "",
"D22301": "100500100",
"D22302": "NikonD850",
"IdLang": "sv",
"D22311": ""
}
{
"IdDim1": "",
"D22301": "100500101",
"D22302": "NikonD850",
"IdLang": "sv",
"D22311": ""
}
Search Query:
{
"size": 500,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "850",
"fields": [
"D22302^3",
"D22301^2",
"D22311^1"
]
}
},
"filter": {
"term": {
"IdLang.keyword": "sv"
}
}
}
}
}
Search Result:
"hits": [
{
"_index": "67638785",
"_type": "_doc",
"_id": "1",
"_score": 0.31608155,
"_source": {
"IdDim1": "",
"D22301": "100500102",
"D22302": "D850Nikon",
"IdLang": "sv",
"D22311": ""
}
},
{
"_index": "67638785",
"_type": "_doc",
"_id": "2",
"_score": 0.31608155,
"_source": {
"IdDim1": "",
"D22301": "100500103",
"D22302": "D850Nikon",
"IdLang": "sv",
"D22311": ""
}
},
{
"_index": "67638785",
"_type": "_doc",
"_id": "3",
"_score": 0.31608155,
"_source": {
"IdDim1": "",
"D22301": "100500100",
"D22302": "NikonD850",
"IdLang": "sv",
"D22311": ""
}
},
{
"_index": "67638785",
"_type": "_doc",
"_id": "4",
"_score": 0.31608155,
"_source": {
"IdDim1": "",
"D22301": "100500101",
"D22302": "NikonD850",
"IdLang": "sv",
"D22311": ""
}
}
]
Upvotes: 2