# Custom Query variables?

**URL:** <https://discuss.elastic.co/t/custom-query-variables/18400>\
**Category:** Elasticsearch\
**Created:** [June 30, 2014, 3:48pm UTC](https://discuss.elastic.co/t/custom-query-variables/18400 "2014-06-30T15:48:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbocto](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@pbocto](https://discuss.elastic.co/u/pbocto)\
**Post date:** [June 30, 2014, 3:48pm UTC](https://discuss.elastic.co/t/custom-query-variables/18400/1 "2014-06-30T15:48:54Z")

</div>

Hi everyone,

I'm creating on my own a little Geocoder. My goal is to be able to retrieve  
a big city or a country with a string on input. This string can be  
mistyped, so I indexed geonames cities5000 data (cities \> 5000 inhab), and  
crossed theses data with countries & admin data. So I got a 46000 cities  
index with country, admin & pop.

I created a search\_field in which I put country, admin & city name +  
alternate names provided in cities5000 file.

I want, within this array, search for a string.

Currently, I'm just searching with a MatchQuery, like "Paris" in  
"search\_field". Unfortunately, the first result is Paris... in Canada...

Still, the "search\_field" data is this one, for Paris (CA) and Paris (FR):

[u'Paris', u'Paris', u'Canada', u'Ontario', u'Ontario']

[u'Paris', u'Paris', u'France', u'\xcele-de-France', u'Ile-de-France', u'Paris', u'Paris']

I don't understand why Paris, CA is first, 'cause there's so much more  
"Paris" in the second one...

Anyway, is there any way to make the number of "my\_query" terms appearance  
make the difference ? Because with alternate names, there will be so much  
much more Paris that it has te count.

Actually I think the array length matters in the scoring and I don't want  
it to... I thought of a custom query score, but I don't think I'm able to  
get the query term in the script query.

Any ideas ?

Thanks !

--  
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/edddf66e-9553-479b-bb68-dfef8b2ba36b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edddf66e-9553-479b-bb68-dfef8b2ba36b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![pbocto](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@pbocto](https://discuss.elastic.co/u/pbocto)\
**Post date:** [July 1, 2014, 8:02am UTC](https://discuss.elastic.co/t/custom-query-variables/18400/2 "2014-07-01T08:02:33Z")

</div>

Up ? Any ideas ?

Le lundi 30 juin 2014 17:48:54 UTC+2, Pierrick Boutruche a écrit :

> Hi everyone,
> 
> I'm creating on my own a little Geocoder. My goal is to be able to  
> retrieve a big city or a country with a string on input. This string can be  
> mistyped, so I indexed geonames cities5000 data (cities \> 5000 inhab), and  
> crossed theses data with countries & admin data. So I got a 46000 cities  
> index with country, admin & pop.
> 
> I created a search\_field in which I put country, admin & city name +  
> alternate names provided in cities5000 file.
> 
> I want, within this array, search for a string.
> 
> Currently, I'm just searching with a MatchQuery, like "Paris" in  
> "search\_field". Unfortunately, the first result is Paris... in Canada...
> 
> Still, the "search\_field" data is this one, for Paris (CA) and Paris (FR):
> 
> [u'Paris', u'Paris', u'Canada', u'Ontario', u'Ontario']
> 
> [u'Paris', u'Paris', u'France', u'\xcele-de-France', u'Ile-de-France', u'Paris', u'Paris']
> 
> I don't understand why Paris, CA is first, 'cause there's so much more  
> "Paris" in the second one...
> 
> Anyway, is there any way to make the number of "my\_query" terms appearance  
> make the difference ? Because with alternate names, there will be so much  
> much more Paris that it has te count.
> 
> Actually I think the array length matters in the scoring and I don't want  
> it to... I thought of a custom query score, but I don't think I'm able to  
> get the query term in the script query.
> 
> Any ideas ?
> 
> Thanks !

--  
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/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 2, 2014, 4:38pm UTC](https://discuss.elastic.co/t/custom-query-variables/18400/3 "2014-07-02T16:38:20Z")

</div>

If you enable explanations, you can see why Lucene the rational behind the  
scoring:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

You are probably correct in that the array length is influencing the  
scoring. By default, Lucene will rate higher fields with fewer terms by  
using length normalization. You can disable norms on the field:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

You can fine-tune better by learning how to read Lucene's explanations. It  
is difficult at first, but it is a useful skill.

Cheers,

Ivan

On Tue, Jul 1, 2014 at 1:02 AM, Pierrick Boutruche [pboutruche@octo.com](mailto:pboutruche@octo.com)  
wrote:

> Up ? Any ideas ?
> 
> Le lundi 30 juin 2014 17:48:54 UTC+2, Pierrick Boutruche a écrit :
> 
> > Hi everyone,
> > 
> > I'm creating on my own a little Geocoder. My goal is to be able to  
> > retrieve a big city or a country with a string on input. This string can be  
> > mistyped, so I indexed geonames cities5000 data (cities \> 5000 inhab), and  
> > crossed theses data with countries & admin data. So I got a 46000 cities  
> > index with country, admin & pop.
> > 
> > I created a search\_field in which I put country, admin & city name +  
> > alternate names provided in cities5000 file.
> > 
> > I want, within this array, search for a string.
> > 
> > Currently, I'm just searching with a MatchQuery, like "Paris" in  
> > "search\_field". Unfortunately, the first result is Paris... in Canada...
> > 
> > Still, the "search\_field" data is this one, for Paris (CA) and Paris (FR):
> > 
> > [u'Paris', u'Paris', u'Canada', u'Ontario', u'Ontario']
> > 
> > [u'Paris', u'Paris', u'France', u'\xcele-de-France', u'Ile-de-France', u'Paris', u'Paris']
> > 
> > I don't understand why Paris, CA is first, 'cause there's so much more  
> > "Paris" in the second one...
> > 
> > Anyway, is there any way to make the number of "my\_query" terms  
> > appearance make the difference ? Because with alternate names, there will  
> > be so much much more Paris that it has te count.
> > 
> > Actually I think the array length matters in the scoring and I don't want  
> > it to... I thought of a custom query score, but I don't think I'm able to  
> > get the query term in the script query.
> > 
> > Any ideas ?
> > 
> > Thanks !
> 
> --  
> 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/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CALY%3DcQCa9nNPX-7oQgjXq6AsFVUyxarDOq9SQ3w6M2MMgT2rNQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCa9nNPX-7oQgjXq6AsFVUyxarDOq9SQ3w6M2MMgT2rNQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [July 2, 2014, 4:45pm UTC](https://discuss.elastic.co/t/custom-query-variables/18400/4 "2014-07-02T16:45:50Z")

</div>

For geo search, it would be a good approach to respect the searchers  
preference by using a locale, so I suggest to add a locale "fr" filter to  
the search.  
Or an origin is added to the start query and all cities are ordered by geo  
distance in relation to the origin. For country search, the origin could be  
the capital city...

Jörg

On Wed, Jul 2, 2014 at 6:38 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> If you enable explanations, you can see why Lucene the rational behind the  
> scoring:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-explain.html)
> 
> You are probably correct in that the array length is influencing the  
> scoring. By default, Lucene will rate higher fields with fewer terms by  
> using length normalization. You can disable norms on the field:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#norms)
> 
> You can fine-tune better by learning how to read Lucene's explanations. It  
> is difficult at first, but it is a useful skill.
> 
> Cheers,
> 
> Ivan
> 
> On Tue, Jul 1, 2014 at 1:02 AM, Pierrick Boutruche [pboutruche@octo.com](mailto:pboutruche@octo.com)  
> wrote:
> 
> > Up ? Any ideas ?
> > 
> > Le lundi 30 juin 2014 17:48:54 UTC+2, Pierrick Boutruche a écrit :
> > 
> > > Hi everyone,
> > > 
> > > I'm creating on my own a little Geocoder. My goal is to be able to  
> > > retrieve a big city or a country with a string on input. This string can be  
> > > mistyped, so I indexed geonames cities5000 data (cities \> 5000 inhab), and  
> > > crossed theses data with countries & admin data. So I got a 46000 cities  
> > > index with country, admin & pop.
> > > 
> > > I created a search\_field in which I put country, admin & city name +  
> > > alternate names provided in cities5000 file.
> > > 
> > > I want, within this array, search for a string.
> > > 
> > > Currently, I'm just searching with a MatchQuery, like "Paris" in  
> > > "search\_field". Unfortunately, the first result is Paris... in Canada...
> > > 
> > > Still, the "search\_field" data is this one, for Paris (CA) and Paris  
> > > (FR):
> > > 
> > > [u'Paris', u'Paris', u'Canada', u'Ontario', u'Ontario']
> > > 
> > > [u'Paris', u'Paris', u'France', u'\xcele-de-France', u'Ile-de-France', u'Paris', u'Paris']
> > > 
> > > I don't understand why Paris, CA is first, 'cause there's so much more  
> > > "Paris" in the second one...
> > > 
> > > Anyway, is there any way to make the number of "my\_query" terms  
> > > appearance make the difference ? Because with alternate names, there will  
> > > be so much much more Paris that it has te count.
> > > 
> > > Actually I think the array length matters in the scoring and I don't  
> > > want it to... I thought of a custom query score, but I don't think I'm able  
> > > to get the query term in the script query.
> > > 
> > > Any ideas ?
> > > 
> > > Thanks !
> > 
> > --  
> > 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/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0f1e6aec-697c-46fc-882e-d8927783fab5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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/CALY%3DcQCa9nNPX-7oQgjXq6AsFVUyxarDOq9SQ3w6M2MMgT2rNQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCa9nNPX-7oQgjXq6AsFVUyxarDOq9SQ3w6M2MMgT2rNQ%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCa9nNPX-7oQgjXq6AsFVUyxarDOq9SQ3w6M2MMgT2rNQ%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCa9nNPX-7oQgjXq6AsFVUyxarDOq9SQ3w6M2MMgT2rNQ%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAKdsXoGUyH0-GBjqAYOrMvuEL\_ERA82MMdGEK2GHCBEmOcGOFg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGUyH0-GBjqAYOrMvuEL_ERA82MMdGEK2GHCBEmOcGOFg%40mail.gmail.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, 1:18am UTC](https://discuss.elastic.co/t/custom-query-variables/18400/5 "2017-07-06T01:18:19Z")

</div>


