# String and Float for a multi\_field?

**URL:** <https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435>\
**Category:** Elasticsearch\
**Created:** [January 27, 2014, 5:14pm UTC](https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435 "2014-01-27T17:14:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur\_Denning](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Arthur\_Denning](https://discuss.elastic.co/u/Arthur_Denning)\
**Post date:** [January 27, 2014, 5:14pm UTC](https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435/1 "2014-01-27T17:14:27Z")

</div>

I have a field that might take string or numeric value, naturally I would  
want to order it numerically if the values turn out to be number.  
I tried to map a multi\_field with both string and float, but it would not  
work if the value is a string. Is there a way to tell elasticsearch to  
ignore indexing a sub-field (in this case, the float field) if the format  
does not fit?  
On the other hand, I know it has been asked before but didn't seem to have  
a good answer, is there a better way to sort string value numerically? Is  
there roadmap for this feature?

--  
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/98f2240e-9fd0-41fe-8daf-0133ab3149df%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/98f2240e-9fd0-41fe-8daf-0133ab3149df%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 27, 2014, 5:51pm UTC](https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435/2 "2014-01-27T17:51:59Z")

</div>

Arthur,

Can you try to set "ignore\_malformed": true for your float field and see if  
that works. Something like this:

```
    "foo": {
      "type": "multi_field",
      "fields": {
        "foo": {
          "type": "string",
          "index": "not_analyzed"
        },
        "f": {
          "type": "float",
          "ignore_malformed": true
        }
      }
    }

```

After that, you should be able to sort numerically on the field "foo.f".

--  
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/600e5a53-17cb-4e16-a959-574c45439210%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/600e5a53-17cb-4e16-a959-574c45439210%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Arthur\_Denning](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Arthur\_Denning](https://discuss.elastic.co/u/Arthur_Denning)\
**Post date:** [January 27, 2014, 6:43pm UTC](https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435/3 "2014-01-27T18:43:10Z")

</div>

Binh, I remember your helpful answer last time. Thanks you again for your  
help!

May I ask you two things more:

1. The doc on sort has a section on cast score for missing values, but is  
there a simple way or setting to ignore missing values altogether?  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html)
2. Do you think the above is a good way to handle the "sort string field  
numerically" issue?

On Tuesday, January 28, 2014 1:51:59 AM UTC+8, Binh Ly wrote:

> Arthur,
> 
> Can you try to set "ignore\_malformed": true for your float field and see  
> if that works. Something like this:
> 
> ```
> "foo": {
> "type": "multi_field",
> "fields": {
> "foo": {
> "type": "string",
> "index": "not_analyzed"
> },
> "f": {
> "type": "float",
> "ignore_malformed": true
> }
> }
> }
> 
> ```
> 
> After that, you should be able to sort numerically on the field "foo.f".

--  
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/00a200ef-b032-42d4-bf8b-6fc455faf3a5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/00a200ef-b032-42d4-bf8b-6fc455faf3a5%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 28, 2014, 2:30pm UTC](https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435/4 "2014-01-28T14:30:28Z")

</div>

Arthur,

1. That section is only to tell ES how to order documents when the field is  
missing. So if you specify for example:

If the price field is missing, the document will be pushed to the bottom of  
the results. But this still does not help when you define multi-fields with  
numeric type and want to store a non-numeric string value.

1. It sounds fine to me. You don't even need a multi-field if you don't  
care about the string value. So for example, you can do something like this:

And then just sort by "foo" numerically.

--  
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/7293f0c9-fafe-49b2-96e3-b0f54396b84c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7293f0c9-fafe-49b2-96e3-b0f54396b84c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:54am UTC](https://discuss.elastic.co/t/string-and-float-for-a-multi-field/15435/5 "2017-07-06T01:54:24Z")

</div>


