I am facing issue in elastic search to find some data with match phrase prefix query.
- If I have value of field is
"shany shores egyptian sa 0976", which I am searching with. - If I will search this field with whole string "shany shores egyptian sa 0976" then it will not return data. And if I search with "shany shores egyptian" it will return same record.
GET my_index/_search
{
"query": {
"match_phrase_prefix": {
"message": {
"query": "shany shores egyptian sa 0976"
}
}
}
}
Result Of It :
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
It will not return any data matching data is there to (shany shores egyptian sa 0976) But, if I will execute same query with following way :
GET my_index/_search
{
"query": {
"match_phrase_prefix": {
"message": {
"query": "shany shores egyptian"
}
}
}
}
Result :
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 12,
"relation": "eq"
},
"max_score": 10.008001,
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 0976",
"message_copy": "shany shores egyptian sa 0976",
"address": {
"suburb": "Egyptian",
"state": "SA",
"postcode": "0976",
"message_copy1": "Shany Shores"
},
"lastUpdatedBy": "User"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 8745",
"message_copy": "shany shores egyptian sa 8745",
"address": {
"suburb": "Egyptian",
"state": "SA",
"postcode": "8745",
"message_copy1": "Shany Shores"
},
"lastUpdatedBy": "User"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 2117",
"message_copy": "shany shores egyptian sa 2117",
"address": {},
"lastUpdatedBy": "string"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 5200",
"message_copy": "shany shores egyptian sa 5200",
"address": {
"suburb": "Egyptian",
"state": "SA",
"postcode": "5200",
"message_copy1": "Shany Shores"
},
"lastUpdatedBy": "User"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 5210",
"message_copy": "shany shores egyptian sa 5210",
"address": {
"suburb": "Egyptian",
"state": "SA",
"postcode": "5210",
"message_copy1": "Shany Shores"
},
"lastUpdatedBy": "User"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 2074",
"message_copy": "shany shores egyptian sa 2074",
"address": {
"suburb": "Egyptian",
"state": "SA",
"postcode": "2074",
"message_copy1": "Shany Shores"
},
"lastUpdatedBy": "User"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 2014",
"message_copy": "shany shores egyptian sa 2014",
"address": {},
"lastUpdatedBy": "string"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 2147",
"message_copy": "shany shores egyptian sa 2147",
"address": {},
"lastUpdatedBy": "string"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 5100",
"message_copy": "shany shores egyptian sa 5100",
"address": {},
"lastUpdatedBy": "string"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_score": 10.008001,
"_source": {
"message": "Shany Shores Egyptian SA 2017",
"message_copy": "shany shores egyptian sa 2017",
"address": {
"suburb": "Egyptian",
"state": "SA",
"postcode": "2017",
"message_copy1": "Shany Shores"
},
"lastUpdatedBy": "User"
}
}
]
}
}
Mapping :
{
"my_index" : {
"mappings" : {
"properties" : {
"_class" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"address" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"message_copy1" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"postcode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"state" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"suburb" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
}
},
"message_copy" : {
"type" : "keyword"
},
"externalIds" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"lastUpdatedBy" : {
"type" : "text"
},
"mappedExternalIds" : {
"type" : "text",
"store" : true
},
"message" : {
"type" : "text",
"analyzer" : "autocomplete_index",
"search_analyzer" : "autocomplete_search"
}
}
}
}
}