# Correct mapping/search query for my data?

**URL:** <https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395>\
**Category:** Elasticsearch\
**Created:** [April 25, 2015, 12:16am UTC](https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395 "2015-04-25T00:16:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)\
**Post date:** [April 25, 2015, 12:16am UTC](https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395/1 "2015-04-25T00:16:17Z")

</div>

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.

$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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/bda701cf-4f64-4cf5-ac5c-2d12458f6d2f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)\
**Post date:** [April 25, 2015, 12:18am UTC](https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395/2 "2015-04-25T00:18:12Z")

</div>

I also don't want the order to matter. e.g. if I typed "meritorious navy"  
vs. "navy meritorious" I should get nearly or exactly the same results.

On Friday, April 24, 2015 at 5:16:18 PM UTC-7, Zelfapp wrote:

> 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.
> 
> $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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cf495227-1fad-4239-8886-9320837144f1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cf495227-1fad-4239-8886-9320837144f1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Suganthi](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@Suganthi](https://discuss.elastic.co/u/Suganthi)\
**Post date:** [April 29, 2015, 9:48pm UTC](https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395/3 "2015-04-29T21:48:25Z")

</div>

The mapping looks good to me. Please refer to the following link on the  
impact of prioritizing-clauses  
[http://www.elastic.co/guide/en/elasticsearch/guide/current/multi-query-strings.html#prioritising-clauses](http://www.elastic.co/guide/en/elasticsearch/guide/current/multi-query-strings.html#prioritising-clauses)  
on bool query.

So looks like you want to score the award\_name matches higher. so you can  
keep that in seperate should clause. And depends on how the other field  
matches or partial matches should contribute to the total score of  
relevance you can group them and keep it in the same level or sub level of  
the bool query.

"query" : {  
"bool" : {  
"should" : [  
{  
"match" : {  
"award\_name" : {  
"boost" : 4,  
"query" : "navy meritorious"  
}  
}  
},  
{ "bool": {  
"should": [  
{ "match": { "ribbon.standard.sku": "navy meritorious" }},  
{ "match": { "search.abbrev\_long": "navy meritorious"}}  
...  
]  
}}

Also the order of the terms in the query doesn't matter, because the search  
analyzer splits "meritorious navy" to two tokens as seen by the below query  
GET /\<index\_name\>/\_analyze?analyzer=full\_name  
{  
"navvy meritorious"  
}  
to  
{  
"token": "navvy",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "",  
"position": 1  
},  
{  
"token": "meritorious",  
"start\_offset": 11,  
"end\_offset": 22,  
"type": "",  
"position": 2  
}

Addressing your next question on boosting score if more query terms appear  
on the award\_name field, that's due to bool match query being field  
centric rather than terms centric.  
please refer to the link  
[http://www.elastic.co/guide/en/elasticsearch/guide/current/\_cross\_fields\_entity\_search.html#\_a\_naive\_approach](http://www.elastic.co/guide/en/elasticsearch/guide/current/_cross_fields_entity_search.html#_a_naive_approach).  
Basically the bool query you have here is same as multi\_match query with  
type set to "most\_fields". As it's being field-centric query that faces  
three common issues (as listed down in  
[Field-Centric Queries | Elasticsearch: The Definitive Guide [2.x] | Elastic](http://www.elastic.co/guide/en/elasticsearch/guide/current/field-centric.html))  
which is exactly the problem statement that you are trying to resolve.

You may verify the same by enclosing your current query with \_validate  
option  
GET ///\_validate/query?explain{  
...  
}

So you may want to try out term-centric query (i.e) cross\_fields query  
([cross-fields Queries | Elasticsearch: The Definitive Guide [2.x] | Elastic](http://www.elastic.co/guide/en/elasticsearch/guide/current/_cross_fields_queries.html)).  
Also you can take advantage of per-field boosting of this query to boost  
award\_name matches.

```
"query": {
    "multi_match": {
        "query": "navy meritorious",
        "type": "cross_fields",
        "fields": [ "award_name^2", "ribbon.standard.sku", 

```

"search.abbrev\_long", "search.data\_code", "search.abbrev\_short" ..]  
}  
}

So you may have your final query in a single multi\_match  
GET ///\_validate/query?explain  
{  
"query": {  
"multi\_match": {  
"query": "navy meritorious",  
"type": "cross\_fields",  
"fields": [  
"award\_name^4",  
"ribbon.standard.sku^2",  
"search.abbrev\_long^2",  
"search.data\_code^2",  
"search.abbrev\_short^2",  
"award\_name.partial^2",  
"ribbon.standard.sku.partial",  
"search.abbrev\_long.partial",  
"search.data\_code.partial",  
"search.abbrev\_short.partial"  
]  
}  
}  
}

or you can combine multiple multi\_match (cross\_fields) queries with bool  
again based on your best needs.  
GET ///\_validate/query?explain  
{  
"query": {  
"bool": {  
"should": [  
{  
"multi\_match": {  
"query": "navy meritorious",  
"type": "cross\_fields",  
"fields": [  
"award\_name^2",  
"ribbon.standard.sku",  
"search.abbrev\_long",  
"search.data\_code",  
"search.abbrev\_short"  
],  
"boost": 2  
}  
},  
{  
"bool": {  
"should": [  
{  
"multi\_match": {  
"query": "navy meritorious",  
"type": "cross\_fields",  
"fields": [  
"award\_name.partial^2",  
"ribbon.standard.sku.partial",  
"search.abbrev\_long.partial",  
"search.data\_code.partial",  
"search.abbrev\_short.partial"  
]  
}  
}  
]  
}  
}  
]  
}  
}  
}

Hope that helps.

On Friday, April 24, 2015 at 5:18:12 PM UTC-7, Zelfapp wrote:

> I also don't want the order to matter. e.g. if I typed "meritorious navy"  
> vs. "navy meritorious" I should get nearly or exactly the same results.
> 
> On Friday, April 24, 2015 at 5:16:18 PM UTC-7, Zelfapp wrote:
> 
> 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.
> 
> $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'
> 
> ...

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f16962f0-a3fc-4da9-afb9-b00d2b88920f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f16962f0-a3fc-4da9-afb9-b00d2b88920f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)\
**Post date:** [April 29, 2015, 10:55pm UTC](https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395/4 "2015-04-29T22:55:36Z")

</div>

First off, thanks for the knowledgeable reply. cross\_fields definitely  
makes a difference in writing and the prioritizing clauses also makes  
sense. Great recommendations.

On Wednesday, April 29, 2015 at 2:48:26 PM UTC-7, Suganthi wrote:

> The mapping looks good to me. Please refer to the following link on the  
> impact of prioritizing-clauses  
> [http://www.elastic.co/guide/en/elasticsearch/guide/current/multi-query-strings.html#prioritising-clauses](http://www.elastic.co/guide/en/elasticsearch/guide/current/multi-query-strings.html#prioritising-clauses)  
> on bool query.
> 
> So looks like you want to score the award\_name matches higher. so you can  
> keep that in seperate should clause. And depends on how the other field  
> matches or partial matches should contribute to the total score of  
> relevance you can group them and keep it in the same level or sub level of  
> the bool query.
> 
> "query" : {  
> "bool" : {  
> "should" : [  
> {  
> "match" : {  
> "award\_name" : {  
> "boost" : 4,  
> "query" : "navy meritorious"  
> }  
> }  
> },  
> { "bool": {  
> "should": [  
> { "match": { "ribbon.standard.sku": "navy meritorious" }},  
> { "match": { "search.abbrev\_long": "navy meritorious"}}  
> ...  
> ]  
> }}
> 
> Also the order of the terms in the query doesn't matter, because the  
> search analyzer splits "meritorious navy" to two tokens as seen by the  
> below query  
> GET /\<index\_name\>/\_analyze?analyzer=full\_name  
> {  
> "navvy meritorious"  
> }  
> to  
> {  
> "token": "navvy",  
> "start\_offset": 5,  
> "end\_offset": 10,  
> "type": "",  
> "position": 1  
> },  
> {  
> "token": "meritorious",  
> "start\_offset": 11,  
> "end\_offset": 22,  
> "type": "",  
> "position": 2  
> }
> 
> Addressing your next question on boosting score if more query terms appear  
> on the award\_name field, that's due to bool match query being field  
> centric rather than terms centric.  
> please refer to the link  
> [http://www.elastic.co/guide/en/elasticsearch/guide/current/\_cross\_fields\_entity\_search.html#\_a\_naive\_approach](http://www.elastic.co/guide/en/elasticsearch/guide/current/_cross_fields_entity_search.html#_a_naive_approach).  
> Basically the bool query you have here is same as multi\_match query with  
> type set to "most\_fields". As it's being field-centric query that faces  
> three common issues (as listed down in  
> [Field-Centric Queries | Elasticsearch: The Definitive Guide [2.x] | Elastic](http://www.elastic.co/guide/en/elasticsearch/guide/current/field-centric.html))  
> which is exactly the problem statement that you are trying to resolve.
> 
> You may verify the same by enclosing your current query with \_validate  
> option  
> GET ///\_validate/query?explain{  
> ...  
> }
> 
> So you may want to try out term-centric query (i.e) cross\_fields query (  
> [cross-fields Queries | Elasticsearch: The Definitive Guide [2.x] | Elastic](http://www.elastic.co/guide/en/elasticsearch/guide/current/_cross_fields_queries.html)).  
> Also you can take advantage of per-field boosting of this query to boost  
> award\_name matches.
> 
> ```
> "query": {
> "multi_match": {
> "query": "navy meritorious",
> "type": "cross_fields",
> "fields": [ "award_name^2", "ribbon.standard.sku", 
> 
> ```
> 
> "search.abbrev\_long", "search.data\_code", "search.abbrev\_short" ..]  
> }  
> }
> 
> So you may have your final query in a single multi\_match  
> GET ///\_validate/query?explain  
> {  
> "query": {  
> "multi\_match": {  
> "query": "navy meritorious",  
> "type": "cross\_fields",  
> "fields": [  
> "award\_name^4",  
> "ribbon.standard.sku^2",  
> "search.abbrev\_long^2",  
> "search.data\_code^2",  
> "search.abbrev\_short^2",  
> "award\_name.partial^2",  
> "ribbon.standard.sku.partial",  
> "search.abbrev\_long.partial",  
> "search.data\_code.partial",  
> "search.abbrev\_short.partial"  
> ]  
> }  
> }  
> }
> 
> or you can combine multiple multi\_match (cross\_fields) queries with bool  
> again based on your best needs.  
> GET ///\_validate/query?explain  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "multi\_match": {  
> "query": "navy meritorious",  
> "type": "cross\_fields",  
> "fields": [  
> "award\_name^2",  
> "ribbon.standard.sku",  
> "search.abbrev\_long",  
> "search.data\_code",  
> "search.abbrev\_short"  
> ],  
> "boost": 2  
> }  
> },  
> {  
> "bool": {  
> "should": [  
> {  
> "multi\_match": {  
> "query": "navy meritorious",  
> "type": "cross\_fields",  
> "fields": [  
> "award\_name.partial^2",  
> "ribbon.standard.sku.partial",  
> "search.abbrev\_long.partial",  
> "search.data\_code.partial",  
> "search.abbrev\_short.partial"  
> ]  
> }  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> Hope that helps.

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/099da52f-3df7-499b-9ae8-ecf63bb80a42%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/099da52f-3df7-499b-9ae8-ecf63bb80a42%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:16am UTC](https://discuss.elastic.co/t/correct-mapping-search-query-for-my-data/23395/5 "2017-07-06T00:16:52Z")

</div>


