This is my php array mapping for my index and type. Below that is the query
I'm currently using and an example of results and the issue I'm not sure
how to fix in either my mapping or in my search query.
Summary of mapping:
- We have partial matching on the award_name field, which is an
alphanumeric string. - We also boost exact matches on the award_name field .
- On the "sku" fields we do the same partial matching and exact matches.
- On the "search" fields we do the same partial matching and exact
matches.
- On the "search" fields we do the same partial matching and exact
$params = [
'index' => 'ezr_v1',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 1,
'analysis' => [
'filter' => [
'name_ngrams' => [
'side' => 'front',
'max_gram' => '10',
'min_gram' => 1,
'type' => 'edgeNGram'
]
],
'analyzer' => [
'full_name' => [
'filter' => [
'standard',
'lowercase'
],
'type' => 'custom',
'tokenizer' => 'standard'
],
'partial_name' => [
'filter' => [
'standard',
'lowercase',
'name_ngrams'
],
'type' => 'custom',
'tokenizer' => 'standard'
]
]
]
],
'mappings' => [
'ezr_' [
'_all' => [
'enabled' => false
],
'properties' => [
'award_name' => [
'fields' => [
'partial' => [
'search_analyzer' => 'full_name',
'index_analyzer' => 'partial_name',
'type' => 'string'
],
'award_name' => [
'type' => 'string',
'analyzer' => 'full_name'
]
],
'type' => 'multi_field'
],
'medal' => [
'properties' => [
'anodized' => [
'properties' => [
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
]
]
],
'standard' => [
'properties' => [
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
]
]
]
]
],
'mini' => [
'properties' => [
'anodized' => [
'properties' => [
'image' => [
'type' => 'string',
'index' => 'no'
],
'price' => [
'type' => 'string',
'index' => 'no'
],
'product_name' => [
'type' => 'string',
'index' => 'no'
],
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
],
'weight' => [
'type' => 'string',
'index' => 'no'
]
]
],
'standard' => [
'properties' => [
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
]
]
]
]
],
'mini_ribbon' => [
'properties' => [
'standard' => [
'properties' => [
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
]
]
]
]
],
'ribbon' => [
'properties' => [
'standard' => [
'properties' => [
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
]
]
],
'thin' => [
'properties' => [
'sku' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'sku' => [
'type' => 'string',
'analyzer' =>
'full_name'
]
],
'type' => 'multi_field'
]
]
]
]
],
'search' => [
'properties' => [
'abbrev_long' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'abbrev_long' => [
'type' => 'string',
'analyzer' => 'full_name'
]
],
'type' => 'multi_field'
],
'abbrev_short' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'abbrev_short' => [
'type' => 'string',
'analyzer' => 'full_name'
]
],
'type' => 'multi_field'
],
'data_code' => [
'fields' => [
'partial' => [
'search_analyzer' =>
'full_name',
'index_analyzer' =>
'partial_name',
'type' => 'string'
],
'data_code' => [
'type' => 'string',
'analyzer' => 'full_name'
]
],
'type' => 'multi_field'
]
]
]
]
]
]
]
];
Bool query:
{
"query" : {
"bool" : {
"should" : [
{
"match" : {
"award_name" : {
"boost" : 4,
"query" : "navy meritorious"
}
}
},
{
"match" : {
"award_name.partial" : "navy meritorious"
}
},
{
"match" : {
"ribbon.standard.sku" : {
"boost" : 1,
"query" : "navy meritorious"
}
}
},
{
"match" : {
"ribbon.standard.sku.partial" : "navy meritorious"
}
},
{
"match" : {
"search.abbrev_long" : {
"boost" : 1,
"query" : "navy meritorious"
}
}
},
{
"match" : {
"search.abbrev_long.partial" : "navy meritorious"
}
},
{
"match" : {
"search.data_code" : {
"boost" : 1,
"query" : "navy meritorious"
}
}
},
{
"match" : {
"search.data_code.partial" : "navy meritorious"
}
},
{
"match" : {
"search.abbrev_short" : {
"boost" : 1,
"query" : "navy meritorious"
}
}
},
{
"match" : {
"search.abbrev_short.partial" : "navy meritorious"
}
}
]
}
}
}
Partial Search Results:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"failed": 0
},
"hits": {
"total": 79,
"max_score": 0.5152277,
"hits": [
{
"_index": "ezrshop.v1",
"type": "ezr",
"_id": "552d9597628062741c000e52",
"_score": 0.5152277,
"_source": {
"award_name": "Navy Cross",
"precedence": {
"army": 30,
"navy": 20,
"marine_corps": 20,
"air_force": 40,
"coast_guard": 20
},
"search": {
"data_code": "MILDECNX",
"abbrev_short": "NC",
"abbrev_long": "NAVY CROSS"
},
"ribbon": {
"standard": {
"product_name": "Navy Cross Medal Ribbon",
"sku": "512 NCMR",
"price": "1.3900",
"weight": "0.015",
"image": "navy_cross_512_ncmr.jpg"
},
"thin": {
"product_name": "Navy Cross Medal Thin Ribbon",
"sku": "138-THR101-7960100",
"price": "0.8900",
"weight": "0.015",
"image": "navy_cross_512_ncmr.jpg"
}
},
"medal": {
"standard": {
"product_name": "Navy Cross Medal",
"sku": "171 NCM",
"price": "69.9900",
"weight": "0.090",
"image": "NavyCross.jpg"
},
"anodized": {
"product_name": "Navy Cross Anodized Medal",
"sku": "6861",
"price": "83.5900",
"weight": "0.090",
"image": "NAVY_CROSS_ANO.jpg"
}
},
"mini": {
"standard": {
"product_name": "Navy Cross Miniature Medal",
"sku": "2071 NAVCROSS-MINI",
"price": "11.4900",
"weight": "0.080",
"image": "NavyCrossMedalFNL.jpg"
},
"anodized": {
"product_name": "Navy Cross Anodized Miniature Medal",
"sku": "7471",
"price": "13.6900",
"weight": "0.090",
"image": "NAVYCROSS_MAND_33XX.jpg"
}
},
"mini_ribbon": {
"standard": {
"product_name": "Navy Cross Medal Mini Ribbon",
"sku": "293-MTR",
"price": "0.8900",
"weight": "0.015",
"image": "navy_cross_512_ncmr_mini.jpg"
}
},
"mongo_id": "552d9597628062741c000e52"
}
},
{
"_index": "ezrshop.v1",
"type": "ezr",
"_id": "552d959c628062741c000e85",
"_score": 0.5143846,
"_source": {
"award_name": "Joint Meritorious Unit Award with
NAVY/AF/MC/CG Frame",
"precedence": {
"army": 470,
"navy": 470,
"marine_corps": 470,
"air_force": 470,
"coast_guard": 510
},
"search": {
"data_code": "UNTAWDJU",
"abbrev_short": "JMUA",
"abbrev_long": "JT MERITORIOUS UNIT AWD"
},
"ribbon": {
"standard": {
"product_name": "Joint Meritorious Unit Award with
NAVY/AF/MC/CG Frame",
"sku": "483 NJMAR",
"price": "2.8000",
"weight": "0.015",
"image":
"joint_meritorious_with_navy_af_mc_cg_frame_483_njmar.jpg"
},
"thin": {
"product_name": "Joint Meritorious Unit Award - Thin
Ribbon with NAVY/AF/MC/CG Frame",
"sku": "SPECTHIN-109-B",
"price": "2.4900",
"weight": "0.015",
"image":
"joint_meritorious_with_navy_af_mc_cg_frame_483_njmar.jpg"
}
},
"mongo_id": "552d959c628062741c000e85"
}
}
The second result is what I want first because the award_name, which is
being boosted has both "meritorious" and "navy" in the string. I know there
is a lot going on here with relevance scoring, but if the award_name
contains more than one parameter regardless of the order I want that award
to score higher. How do I do that in either my mapping/analyzers or in my
search query?
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bda701cf-4f64-4cf5-ac5c-2d12458f6d2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.