DSL query, fields not coming in same order in result


(sumitimes) #1

I have a query like this the output expected is in order of fields specified.
name (String)
price (Double)
year (Integer)

but i am getting
price
year
name

so it is automatically getting sorted to put string last, is there anyway to enforce that i recieve result in same order as whatever is specified in fields

"fields": [
"name",
"price",
"year"
]

Query:
{
"fields": [
"name",
"price",
"year"
],
"from": 10,
"size": 5,
"sort": [],
"filter": {
"query": {
"query_string": {
"query": "/products(name:name)"
}
}
}
}


(sumitimes) #2

can anyone suggest how to solve it, really appreciate any help


(Shay Banon) #3

You mean sorting by it? When you specify fields, those are the fields that
will be returned as part of each hit, not sorting. There is a whole sorting
section that controls sorting.

On Wed, May 30, 2012 at 9:40 AM, sumitimes sumitimes@gmail.com wrote:

I have a query like this the output expected is in order of fields
specified.
name (String)
price (Double)
year (Integer)

but i am getting
price
year
name

so it is automatically getting sorted to put string last, is there anyway
to
enforce that i recieve result in same order as whatever is specified in
fields

"fields": [
"name",
"price",
"year"
]

Query:
{
"fields": [
"name",
"price",
"year"
],
"from": 10,
"size": 5,
"sort": [],
"filter": {
"query": {
"query_string": {
"query": "/products(name:name)"
}
}
}
}

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/DSL-query-fields-not-coming-in-same-order-in-result-tp4018535.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(sumitimes) #4

Hi kimchy,

Thanks for the response, i am not talking about sorting, sorting decides
order of each record, here i am concerned about order of fields in each
record
say for example

Sorting will do something like this

record 1

Columns fName Lname age

Record 1 sam tom 20

Record 2 vim jones 25

sorted by Lname will return

Record 1 vim jones 25

Record 2 sam tom 20

for me this is will be worong
*
Columns age fName Lname *
I expect
*Columns fName Lname age *only, not worried by order of records but order
of columns

sorted by fname will return again records which are arranged

On Sun, Jun 3, 2012 at 3:38 PM, kimchy [via ElasticSearch Users] <
ml-node+s115913n4018741h52@n3.nabble.com> wrote:

You mean sorting by it? When you specify fields, those are the fields that
will be returned as part of each hit, not sorting. There is a whole sorting
section that controls sorting.

On Wed, May 30, 2012 at 9:40 AM, sumitimes <[hidden email]http://user/SendEmail.jtp?type=node&node=4018741&i=0

wrote:

I have a query like this the output expected is in order of fields
specified.
name (String)
price (Double)
year (Integer)

but i am getting
price
year
name

so it is automatically getting sorted to put string last, is there anyway
to
enforce that i recieve result in same order as whatever is specified in
fields

"fields": [
"name",
"price",
"year"
]

Query:
{
"fields": [
"name",
"price",
"year"
],
"from": 10,
"size": 5,
"sort": [],
"filter": {
"query": {
"query_string": {
"query": "/products(name:name)"
}
}
}
}

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/DSL-query-fields-not-coming-in-same-order-in-result-tp4018535.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


If you reply to this email, your message will be added to the discussion
below:

http://elasticsearch-users.115913.n3.nabble.com/DSL-query-fields-not-coming-in-same-order-in-result-tp4018535p4018741.html
To unsubscribe from DSL query, fields not coming in same order in result, click
herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4018535&code=c3VtaXRpbWVzQGdtYWlsLmNvbXw0MDE4NTM1fDcwMzYwNDU3OQ==
.
NAMLhttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers!nabble%3Aemail.naml-instant_emails!nabble%3Aemail.naml-send_instant_email!nabble%3Aemail.naml


(Clinton Gormley) #5

Thanks for the response, i am not talking about sorting, sorting
decides order of each record, here i am concerned about order of
fields in each record

JSON objects are by definition, an unordered collection of key:value
pairs. Even if ES were to return the "fields" object in a particular
order, as soon as you parse JSON the order may be changed.

clint


(sumitimes) #6

Thanks for you response, we are using elastic search as a intermediate
data, we are doing very complex compiling and de compiling of data , and
our front end expects order of fields to be maintained, so i wanted as much
functionality i can get directly, anyways we ended up writing a json parser
which will maintain field order.

Thank you all for all your suggestions !!!

On Fri, Jun 8, 2012 at 8:20 PM, Clinton Gormley-2 [via ElasticSearch Users]
ml-node+s115913n4018977h68@n3.nabble.com wrote:

Thanks for the response, i am not talking about sorting, sorting
decides order of each record, here i am concerned about order of
fields in each record

JSON objects are by definition, an unordered collection of key:value
pairs. Even if ES were to return the "fields" object in a particular
order, as soon as you parse JSON the order may be changed.

clint


If you reply to this email, your message will be added to the discussion
below:

http://elasticsearch-users.115913.n3.nabble.com/DSL-query-fields-not-coming-in-same-order-in-result-tp4018535p4018977.html
To unsubscribe from DSL query, fields not coming in same order in result, click
herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4018535&code=c3VtaXRpbWVzQGdtYWlsLmNvbXw0MDE4NTM1fDcwMzYwNDU3OQ==
.
NAMLhttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers!nabble%3Aemail.naml-instant_emails!nabble%3Aemail.naml-send_instant_email!nabble%3Aemail.naml


(system) #7