# How to index documents without location field?

**URL:** <https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534>\
**Category:** Elasticsearch\
**Created:** [July 8, 2014, 4:16pm UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534 "2014-07-08T16:16:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [July 8, 2014, 4:16pm UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/1 "2014-07-08T16:16:43Z")

</div>

HI,

I need to index a mix of documents, some of which needs to be indexed using  
geo\_point with a location fields but there are some other documents which  
don't contain location field. Whenever I do indexing, I keep getting Mapper  
parsing exception with location={} during indexing and elasticsearch stops  
importing documents. Can anyone give me any idea how to work around the  
problem ?

Also, My requirement needs me to give search results based on location  
based biasing. I have  
read [http://www.elasticsearch.org/blog/geo-location-and-search/](http://www.elasticsearch.org/blog/geo-location-and-search/) but not  
able to fit it in my usecase. Since I have a mix of documents, I can't  
simply sort on the basis of geo distance since it will put documents  
without location field either at top or at bottom while sorting. Can anyone  
tell me how can I apply sorting only on top k results. I have read about  
Query rescorer but I can't use it. I need to apply location based sorting  
only when a certain documents are returned. Based on that I need to make a  
decision whether to apply sorting or not. If I'll use rescorer it will  
rescore documents everytime. Is there anyway by which I can incorporate  
weight of location based score in normal score. Default can 0 and if some  
score x comes, use F(x). My problem is getting a proper formula for the  
case and how to use it in a query ?

Looking forward for your help !!!

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/d38363da-f291-4b20-a403-a0fc5e729e18%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d38363da-f291-4b20-a403-a0fc5e729e18%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 8, 2014, 4:21pm UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/2 "2014-07-08T16:21:24Z")

</div>

In terms of the parsing exception, can you simply index the document with  
the field entirely?

As far as sorting goes, it makes sense to push the location-less documents  
to the top or bottom. You lost me on the part regarding the rescorer. Do  
you need the location-less documents to be returned in your query?

--  
Ivan

On Tue, Jul 8, 2014 at 9:16 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> HI,
> 
> I need to index a mix of documents, some of which needs to be indexed  
> using geo\_point with a location fields but there are some other documents  
> which don't contain location field. Whenever I do indexing, I keep getting  
> Mapper parsing exception with location={} during indexing and elasticsearch  
> stops importing documents. Can anyone give me any idea how to work around  
> the problem ?
> 
> Also, My requirement needs me to give search results based on location  
> based biasing. I have read  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/geo-location-and-search/) but not able  
> to fit it in my usecase. Since I have a mix of documents, I can't simply  
> sort on the basis of geo distance since it will put documents without  
> location field either at top or at bottom while sorting. Can anyone tell me  
> how can I apply sorting only on top k results. I have read about Query  
> rescorer but I can't use it. I need to apply location based sorting only  
> when a certain documents are returned. Based on that I need to make a  
> decision whether to apply sorting or not. If I'll use rescorer it will  
> rescore documents everytime. Is there anyway by which I can incorporate  
> weight of location based score in normal score. Default can 0 and if some  
> score x comes, use F(x). My problem is getting a proper formula for the  
> case and how to use it in a query ?
> 
> Looking forward for your help !!!
> 
> 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/d38363da-f291-4b20-a403-a0fc5e729e18%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d38363da-f291-4b20-a403-a0fc5e729e18%40googlegroups.com)  
> .  
> 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%3DcQBYYOapE9Q0kVmhDmsVH%3D5KqDNafYh8TdXR9p6aOY7h9g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBYYOapE9Q0kVmhDmsVH%3D5KqDNafYh8TdXR9p6aOY7h9g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [July 8, 2014, 5:52pm UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/3 "2014-07-08T17:52:54Z")

</div>

Yes, I can index the documents which contain location field but not those  
documents which don't contain location field. It gives a parsing exception  
in that case and then stops importing documents. Is there anyway by which I  
can tell the ES that index location if it's present otherwise skip it ?

Actually I have a mix of documents (some contains location and some are  
without location), now let's say,result of a user query is a document which  
don't contain location field, Now if I do a sorting this will put that  
document in the last/first position. In this case, it will work but not in  
other cases where actual result needs to be a location based document. So,  
sorting won't fix my issue. I don't know always whether to put location  
missing document on top/bottom position.

For query Rescorer, I'm not able to understand how can I apply it to the  
top k results from the first query. How to rescore based on location ?  
On quick Googling I found this:

"query": {  
"function\_score": {  
"functions": [  
{ "gauss": { "loc": { "origin": "51,0", "scale": "5km" }}},  
]  
}  
}

But, this is something similar to sorting, right ? Also, there might be a  
case in which you gave some score based on location field to a document.  
Now another document exist without location field so in this case your  
default score will be 0 and chances are that the actual match was this  
document(without location) which should come on the top but due to  
rescoring its score has reduced and it will not appear on top. How to  
tackle this kind of problem ?

What I need something like this: I should first query ES, then inspect the  
results and decide if I really need location based biasing based on the  
results. If results of a query is a document which don't contain location  
field, the I know location based biasing will badly affect results. So, I  
won't go for location based biasing but let's say I got a result which  
contains a location field, so I'll go for a location based biasing.  
Something like conditional biasing. Is there any way by which I can use the  
result of response again for manipulation because querying again will take  
a lot of time ?

Accept my apology if I'm not making things a bit clearer. Please don't  
hesitate to ask further questions for clarity.  
Thanks

On Tuesday, 8 July 2014 21:51:29 UTC+5:30, Ivan Brusic wrote:

> In terms of the parsing exception, can you simply index the document with  
> the field entirely?
> 
> As far as sorting goes, it makes sense to push the location-less documents  
> to the top or bottom. You lost me on the part regarding the rescorer. Do  
> you need the location-less documents to be returned in your query?
> 
> --  
> Ivan
> 
> On Tue, Jul 8, 2014 at 9:16 AM, coder \<[mukul...@gmail.com](mailto:mukul...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > HI,
> > 
> > I need to index a mix of documents, some of which needs to be indexed  
> > using geo\_point with a location fields but there are some other documents  
> > which don't contain location field. Whenever I do indexing, I keep getting  
> > Mapper parsing exception with location={} during indexing and elasticsearch  
> > stops importing documents. Can anyone give me any idea how to work around  
> > the problem ?
> > 
> > Also, My requirement needs me to give search results based on location  
> > based biasing. I have read  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/geo-location-and-search/) but not able  
> > to fit it in my usecase. Since I have a mix of documents, I can't simply  
> > sort on the basis of geo distance since it will put documents without  
> > location field either at top or at bottom while sorting. Can anyone tell me  
> > how can I apply sorting only on top k results. I have read about Query  
> > rescorer but I can't use it. I need to apply location based sorting only  
> > when a certain documents are returned. Based on that I need to make a  
> > decision whether to apply sorting or not. If I'll use rescorer it will  
> > rescore documents everytime. Is there anyway by which I can incorporate  
> > weight of location based score in normal score. Default can 0 and if some  
> > score x comes, use F(x). My problem is getting a proper formula for the  
> > case and how to use it in a query ?
> > 
> > Looking forward for your help !!!
> > 
> > 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/d38363da-f291-4b20-a403-a0fc5e729e18%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d38363da-f291-4b20-a403-a0fc5e729e18%40googlegroups.com)  
> > .  
> > 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/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%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 8, 2014, 5:59pm UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/4 "2014-07-08T17:59:42Z")

</div>

I made a very important mistake in my first response. What I meant to say is

Can you simply index the document WITHOUT the field entirely?

What it appears that you are doing is indexing a field with no value. One  
solution would be to simply omit the field altogether. Elasticsearch/Lucene  
is scheme-less, so you can index a document without a field compared to the  
other documents. The mapper is only used on fields that exist. If this is  
not the case, can you provide a sample document?

--  
Ivan

On Tue, Jul 8, 2014 at 10:52 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> Yes, I can index the documents which contain location field but not those  
> documents which don't contain location field. It gives a parsing exception  
> in that case and then stops importing documents. Is there anyway by which I  
> can tell the ES that index location if it's present otherwise skip it ?
> 
> Actually I have a mix of documents (some contains location and some are  
> without location), now let's say,result of a user query is a document which  
> don't contain location field, Now if I do a sorting this will put that  
> document in the last/first position. In this case, it will work but not in  
> other cases where actual result needs to be a location based document. So,  
> sorting won't fix my issue. I don't know always whether to put location  
> missing document on top/bottom position.
> 
> For query Rescorer, I'm not able to understand how can I apply it to the  
> top k results from the first query. How to rescore based on location ?  
> On quick Googling I found this:
> 
> "query": {  
> "function\_score": {  
> "functions": [  
> { "gauss": { "loc": { "origin": "51,0", "scale": "5km" }}},  
> ]  
> }  
> }
> 
> But, this is something similar to sorting, right ? Also, there might be a  
> case in which you gave some score based on location field to a document.  
> Now another document exist without location field so in this case your  
> default score will be 0 and chances are that the actual match was this  
> document(without location) which should come on the top but due to  
> rescoring its score has reduced and it will not appear on top. How to  
> tackle this kind of problem ?
> 
> What I need something like this: I should first query ES, then inspect the  
> results and decide if I really need location based biasing based on the  
> results. If results of a query is a document which don't contain location  
> field, the I know location based biasing will badly affect results. So, I  
> won't go for location based biasing but let's say I got a result which  
> contains a location field, so I'll go for a location based biasing.  
> Something like conditional biasing. Is there any way by which I can use the  
> result of response again for manipulation because querying again will take  
> a lot of time ?
> 
> Accept my apology if I'm not making things a bit clearer. Please don't  
> hesitate to ask further questions for clarity.  
> Thanks
> 
> On Tuesday, 8 July 2014 21:51:29 UTC+5:30, Ivan Brusic wrote:
> 
> > In terms of the parsing exception, can you simply index the document with  
> > the field entirely?
> > 
> > As far as sorting goes, it makes sense to push the location-less  
> > documents to the top or bottom. You lost me on the part regarding the  
> > rescorer. Do you need the location-less documents to be returned in your  
> > query?
> > 
> > --  
> > Ivan
> > 
> > On Tue, Jul 8, 2014 at 9:16 AM, coder [mukul...@gmail.com](mailto:mukul...@gmail.com) wrote:
> > 
> > > HI,
> > > 
> > > I need to index a mix of documents, some of which needs to be indexed  
> > > using geo\_point with a location fields but there are some other documents  
> > > which don't contain location field. Whenever I do indexing, I keep getting  
> > > Mapper parsing exception with location={} during indexing and elasticsearch  
> > > stops importing documents. Can anyone give me any idea how to work around  
> > > the problem ?
> > > 
> > > Also, My requirement needs me to give search results based on location  
> > > based biasing. I have read [http://www.elasticsearch](http://www.elasticsearch).  
> > > org/blog/geo-location-and-search/ but not able to fit it in my usecase.  
> > > Since I have a mix of documents, I can't simply sort on the basis of geo  
> > > distance since it will put documents without location field either at top  
> > > or at bottom while sorting. Can anyone tell me how can I apply sorting only  
> > > on top k results. I have read about Query rescorer but I can't use it. I  
> > > need to apply location based sorting only when a certain documents are  
> > > returned. Based on that I need to make a decision whether to apply sorting  
> > > or not. If I'll use rescorer it will rescore documents everytime. Is there  
> > > anyway by which I can incorporate weight of location based score in normal  
> > > score. Default can 0 and if some score x comes, use F(x). My problem is  
> > > getting a proper formula for the case and how to use it in a query ?
> > > 
> > > Looking forward for your help !!!
> > > 
> > > 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/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/d38363da-f291-4b20-a403-a0fc5e729e18%  
> > > [40googlegroups.com](http://40googlegroups.com).  
> > > 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/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%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%3DcQBDr9Q3%2Bt1ydYBG7krdRRcAqkuYgPENSca6ta31%3DpWM7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBDr9Q3%2Bt1ydYBG7krdRRcAqkuYgPENSca6ta31%3DpWM7w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [July 8, 2014, 6:04pm UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/5 "2014-07-08T18:04:17Z")

</div>

yes, I got it. You are right Ivan. I think I should omit the field  
altogether because that way it won't find that field and will not try to  
index it. I think that should work. I'll try it and will let you know if  
that works.

But how can I make the use of that location field is also very important.  
Can you give some of your precious time to answer the second part of the  
question. It will be a great help for me.

Thanks

On Tuesday, 8 July 2014 23:29:49 UTC+5:30, Ivan Brusic wrote:

> I made a very important mistake in my first response. What I meant to say  
> is
> 
> Can you simply index the document WITHOUT the field entirely?
> 
> What it appears that you are doing is indexing a field with no value. One  
> solution would be to simply omit the field altogether. Elasticsearch/Lucene  
> is scheme-less, so you can index a document without a field compared to the  
> other documents. The mapper is only used on fields that exist. If this is  
> not the case, can you provide a sample document?
> 
> --  
> Ivan
> 
> On Tue, Jul 8, 2014 at 10:52 AM, coder \<[mukul...@gmail.com](mailto:mukul...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Yes, I can index the documents which contain location field but not those  
> > documents which don't contain location field. It gives a parsing exception  
> > in that case and then stops importing documents. Is there anyway by which I  
> > can tell the ES that index location if it's present otherwise skip it ?
> > 
> > Actually I have a mix of documents (some contains location and some are  
> > without location), now let's say,result of a user query is a document which  
> > don't contain location field, Now if I do a sorting this will put that  
> > document in the last/first position. In this case, it will work but not in  
> > other cases where actual result needs to be a location based document. So,  
> > sorting won't fix my issue. I don't know always whether to put location  
> > missing document on top/bottom position.
> > 
> > For query Rescorer, I'm not able to understand how can I apply it to the  
> > top k results from the first query. How to rescore based on location ?  
> > On quick Googling I found this:
> > 
> > "query": {  
> > "function\_score": {  
> > "functions": [  
> > { "gauss": { "loc": { "origin": "51,0", "scale": "5km" }}},  
> > ]  
> > }  
> > }
> > 
> > But, this is something similar to sorting, right ? Also, there might be a  
> > case in which you gave some score based on location field to a document.  
> > Now another document exist without location field so in this case your  
> > default score will be 0 and chances are that the actual match was this  
> > document(without location) which should come on the top but due to  
> > rescoring its score has reduced and it will not appear on top. How to  
> > tackle this kind of problem ?
> > 
> > What I need something like this: I should first query ES, then inspect  
> > the results and decide if I really need location based biasing based on the  
> > results. If results of a query is a document which don't contain location  
> > field, the I know location based biasing will badly affect results. So, I  
> > won't go for location based biasing but let's say I got a result which  
> > contains a location field, so I'll go for a location based biasing.  
> > Something like conditional biasing. Is there any way by which I can use the  
> > result of response again for manipulation because querying again will take  
> > a lot of time ?
> > 
> > Accept my apology if I'm not making things a bit clearer. Please don't  
> > hesitate to ask further questions for clarity.  
> > Thanks
> > 
> > On Tuesday, 8 July 2014 21:51:29 UTC+5:30, Ivan Brusic wrote:
> > 
> > > In terms of the parsing exception, can you simply index the document  
> > > with the field entirely?
> > > 
> > > As far as sorting goes, it makes sense to push the location-less  
> > > documents to the top or bottom. You lost me on the part regarding the  
> > > rescorer. Do you need the location-less documents to be returned in your  
> > > query?
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Tue, Jul 8, 2014 at 9:16 AM, coder [mukul...@gmail.com](mailto:mukul...@gmail.com) wrote:
> > > 
> > > > HI,
> > > > 
> > > > I need to index a mix of documents, some of which needs to be indexed  
> > > > using geo\_point with a location fields but there are some other documents  
> > > > which don't contain location field. Whenever I do indexing, I keep getting  
> > > > Mapper parsing exception with location={} during indexing and elasticsearch  
> > > > stops importing documents. Can anyone give me any idea how to work around  
> > > > the problem ?
> > > > 
> > > > Also, My requirement needs me to give search results based on location  
> > > > based biasing. I have read [http://www.elasticsearch](http://www.elasticsearch).  
> > > > org/blog/geo-location-and-search/ but not able to fit it in my  
> > > > usecase. Since I have a mix of documents, I can't simply sort on the basis  
> > > > of geo distance since it will put documents without location field either  
> > > > at top or at bottom while sorting. Can anyone tell me how can I apply  
> > > > sorting only on top k results. I have read about Query rescorer but I can't  
> > > > use it. I need to apply location based sorting only when a certain  
> > > > documents are returned. Based on that I need to make a decision whether to  
> > > > apply sorting or not. If I'll use rescorer it will rescore documents  
> > > > everytime. Is there anyway by which I can incorporate weight of location  
> > > > based score in normal score. Default can 0 and if some score x comes, use  
> > > > F(x). My problem is getting a proper formula for the case and how to use it  
> > > > in a query ?
> > > > 
> > > > Looking forward for your help !!!
> > > > 
> > > > 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/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/d38363da-f291-4b20-a403-a0fc5e729e18%  
> > > > [40googlegroups.com](http://40googlegroups.com).  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%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/919e7d5d-bf21-477e-ae83-1504eeed7368%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/919e7d5d-bf21-477e-ae83-1504eeed7368%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 9, 2014, 7:05am UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/6 "2014-07-09T07:05:07Z")

</div>

Now that I am not at work, I had a chance t finally read your posts more  
carefully. I guess what you are looking for is a way to dynamically change  
the sort based on the result set? That is a tough challenge. Query rescorer  
will not work since it only works on the top k, aka after the documents are  
already sorted.

One hack I can think of is if you provide a custom sort value for the  
missing values [1] and you can look for this value in the query rescorer.  
If present, then apply some other scoring, if not leave it be. You cannot  
know the values of the other documents in the top k result set.

Top bad you can't apply facets to the top n results (I don't think  
aggregations support this feature either), because you could of aggregated  
the location field and detect how many documents are missing the field  
based on the aggregation values.

[1]

> **[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.

Cheers,

Ivan

On Tue, Jul 8, 2014 at 11:04 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> yes, I got it. You are right Ivan. I think I should omit the field  
> altogether because that way it won't find that field and will not try to  
> index it. I think that should work. I'll try it and will let you know if  
> that works.
> 
> But how can I make the use of that location field is also very important.  
> Can you give some of your precious time to answer the second part of the  
> question. It will be a great help for me.
> 
> Thanks
> 
> On Tuesday, 8 July 2014 23:29:49 UTC+5:30, Ivan Brusic wrote:
> 
> > I made a very important mistake in my first response. What I meant to say  
> > is
> > 
> > Can you simply index the document WITHOUT the field entirely?
> > 
> > What it appears that you are doing is indexing a field with no value. One  
> > solution would be to simply omit the field altogether. Elasticsearch/Lucene  
> > is scheme-less, so you can index a document without a field compared to the  
> > other documents. The mapper is only used on fields that exist. If this is  
> > not the case, can you provide a sample document?
> > 
> > --  
> > Ivan
> > 
> > On Tue, Jul 8, 2014 at 10:52 AM, coder [mukul...@gmail.com](mailto:mukul...@gmail.com) wrote:
> > 
> > > Yes, I can index the documents which contain location field but not  
> > > those documents which don't contain location field. It gives a parsing  
> > > exception in that case and then stops importing documents. Is there anyway  
> > > by which I can tell the ES that index location if it's present otherwise  
> > > skip it ?
> > > 
> > > Actually I have a mix of documents (some contains location and some are  
> > > without location), now let's say,result of a user query is a document which  
> > > don't contain location field, Now if I do a sorting this will put that  
> > > document in the last/first position. In this case, it will work but not in  
> > > other cases where actual result needs to be a location based document. So,  
> > > sorting won't fix my issue. I don't know always whether to put location  
> > > missing document on top/bottom position.
> > > 
> > > For query Rescorer, I'm not able to understand how can I apply it to the  
> > > top k results from the first query. How to rescore based on location ?  
> > > On quick Googling I found this:
> > > 
> > > "query": {  
> > > "function\_score": {  
> > > "functions": [  
> > > { "gauss": { "loc": { "origin": "51,0", "scale": "5km" }}},  
> > > ]  
> > > }  
> > > }
> > > 
> > > But, this is something similar to sorting, right ? Also, there might be  
> > > a case in which you gave some score based on location field to a document.  
> > > Now another document exist without location field so in this case your  
> > > default score will be 0 and chances are that the actual match was this  
> > > document(without location) which should come on the top but due to  
> > > rescoring its score has reduced and it will not appear on top. How to  
> > > tackle this kind of problem ?
> > > 
> > > What I need something like this: I should first query ES, then inspect  
> > > the results and decide if I really need location based biasing based on the  
> > > results. If results of a query is a document which don't contain location  
> > > field, the I know location based biasing will badly affect results. So, I  
> > > won't go for location based biasing but let's say I got a result which  
> > > contains a location field, so I'll go for a location based biasing.  
> > > Something like conditional biasing. Is there any way by which I can use the  
> > > result of response again for manipulation because querying again will take  
> > > a lot of time ?
> > > 
> > > Accept my apology if I'm not making things a bit clearer. Please don't  
> > > hesitate to ask further questions for clarity.  
> > > Thanks
> > > 
> > > On Tuesday, 8 July 2014 21:51:29 UTC+5:30, Ivan Brusic wrote:
> > > 
> > > > In terms of the parsing exception, can you simply index the document  
> > > > with the field entirely?
> > > > 
> > > > As far as sorting goes, it makes sense to push the location-less  
> > > > documents to the top or bottom. You lost me on the part regarding the  
> > > > rescorer. Do you need the location-less documents to be returned in your  
> > > > query?
> > > > 
> > > > --  
> > > > Ivan
> > > > 
> > > > On Tue, Jul 8, 2014 at 9:16 AM, coder [mukul...@gmail.com](mailto:mukul...@gmail.com) wrote:
> > > > 
> > > > > HI,
> > > > > 
> > > > > I need to index a mix of documents, some of which needs to be indexed  
> > > > > using geo\_point with a location fields but there are some other documents  
> > > > > which don't contain location field. Whenever I do indexing, I keep getting  
> > > > > Mapper parsing exception with location={} during indexing and elasticsearch  
> > > > > stops importing documents. Can anyone give me any idea how to work around  
> > > > > the problem ?
> > > > > 
> > > > > Also, My requirement needs me to give search results based on location  
> > > > > based biasing. I have read [http://www.elasticsearch](http://www.elasticsearch).  
> > > > > org/blog/geo-location-and-search/ but not able to fit it in my  
> > > > > usecase. Since I have a mix of documents, I can't simply sort on the basis  
> > > > > of geo distance since it will put documents without location field either  
> > > > > at top or at bottom while sorting. Can anyone tell me how can I apply  
> > > > > sorting only on top k results. I have read about Query rescorer but I can't  
> > > > > use it. I need to apply location based sorting only when a certain  
> > > > > documents are returned. Based on that I need to make a decision whether to  
> > > > > apply sorting or not. If I'll use rescorer it will rescore documents  
> > > > > everytime. Is there anyway by which I can incorporate weight of location  
> > > > > based score in normal score. Default can 0 and if some score x comes, use  
> > > > > F(x). My problem is getting a proper formula for the case and how to use it  
> > > > > in a query ?
> > > > > 
> > > > > Looking forward for your help !!!
> > > > > 
> > > > > 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/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/d38363da-f291-4b20-a403-a0fc5e729e18%40goo  
> > > > > [glegroups.com](http://glegroups.com).  
> > > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/68e2bb95-453c-476c-a8ec-8487aca2fba5%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/919e7d5d-bf21-477e-ae83-1504eeed7368%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/919e7d5d-bf21-477e-ae83-1504eeed7368%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/919e7d5d-bf21-477e-ae83-1504eeed7368%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/919e7d5d-bf21-477e-ae83-1504eeed7368%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%3DcQCAZYO04UhGGT5Q9udKi0e1ipp46gRgcdV31W%3DBnwp4cw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCAZYO04UhGGT5Q9udKi0e1ipp46gRgcdV31W%3DBnwp4cw%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:17am UTC](https://discuss.elastic.co/t/how-to-index-documents-without-location-field/18534/7 "2017-07-06T01:17:07Z")

</div>


