String and Float for a multi_field?

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.
To view this discussion on the web visit 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.

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.
To view this discussion on the web visit 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.

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
  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.
To view this discussion on the web visit 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.

Arthur,

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

    "sort" : [
    { "price" : {"missing" : "_last"} },
    ]

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:

     "foo": {
           "type": "float",
           "ignore_malformed": true
     }
    

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.
To view this discussion on the web visit 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.