Parent/child sort

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not correctly
specified in the sorting, but how to specify the correctly for sorting for
childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": [],
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should": []
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": [],
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

The query in the email doesn't use the has_child query, so I don't know
what you mean with sorting for childs. So in this case you're searching for
product documents, and from the script you send I see that this document
type has a location field, so that will just sort any product document that
matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
Document relations - Berlin Buzzwords 2013 | PPT (last slide)

On 4 September 2013 23:06, Max Seleznev max@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

sorry, I mixed queries.
I attached file with the request, if you started it then you will see two
requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen wrote:

The query in the email doesn't use the has_child query, so I don't know
what you mean with sorting for childs. So in this case you're searching for
product documents, and from the script you send I see that this document
type has a location field, so that will just sort any product document that
matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
Document relations - Berlin Buzzwords 2013 | PPT (last
slide)

On 4 September 2013 23:06, Max Seleznev <m...@inetgiant.com <javascript:>>wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

--
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 <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Did you see the last slide of the presentation I mentioned in my previous
reply?
What you need to do is move the sorting part to a custom_score query and
put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev max@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will see two
requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen wrote:

The query in the email doesn't use the has_child query, so I don't know
what you mean with sorting for childs. So in this case you're searching for
product documents, and from the script you send I see that this document
type has a location field, so that will just sort any product document that
matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**martijnvg/document-**relationsbbuz2013http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

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

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[Failed to execute phase
    [query_fetch], total failure; shardFailures
    {[8xa0yPbjREmk8DuC_jlipA][testparentfacets][0]:
    RemoteTransportException[[T-Ray][inet[/10.0.10.223:9301]][search/phase/query+fetch]];
    nested: QueryPhaseExecutionException[[testparentfacets][0]:
    query[ChildrenQuery[product/group](custom score
    (ConstantScore(:),function=script[doc['location'].distance(lat, lon)],
    params [null]))],from[0],size[10]: Query Failed [failed to execute
    context rewrite]]; nested: PropertyAccessException[[Error: unresolvable
    property or identifier: lat] [Near : {... doc['location'].distance(lat,
    lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen wrote:

Did you see the last slide of the presentation I mentioned in my previous
reply?
What you need to do is move the sorting part to a custom_score query and
put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev <m...@inetgiant.com <javascript:>>wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will see two
requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen
wrote:

The query in the email doesn't use the has_child query, so I don't know
what you mean with sorting for childs. So in this case you're searching for
product documents, and from the script you send I see that this document
type has a location field, so that will just sort any product document that
matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**martijnvg/document-**relationsbbuz2013http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

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

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

You need to substitute the lat and long variables in the script with the
actual values:
"script": "doc['location'].distance(40.6234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev max@inetgiant.com wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[Failed to execute phase
    [query_fetch], total failure; shardFailures
    {[8xa0yPbjREmk8DuC_jlipA][testparentfacets][0]:
    RemoteTransportException[[T-Ray][inet[/10.0.10.223:9301]][search/phase/query+fetch]];
    nested: QueryPhaseExecutionException[[testparentfacets][0]:
    query[ChildrenQuery[product/group](custom score
    (ConstantScore(:),function=script[doc['location'].distance(lat, lon)],
    params [null]))],from[0],size[10]: Query Failed [failed to execute
    context rewrite]]; nested: PropertyAccessException[[Error: unresolvable
    property or identifier: lat] [Near : {... doc['location'].distance(lat,
    lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen wrote:

Did you see the last slide of the presentation I mentioned in my previous
reply?
What you need to do is move the sorting part to a custom_score query and
put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will see
two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen
wrote:

The query in the email doesn't use the has_child query, so I don't know
what you mean with sorting for childs. So in this case you're searching for
product documents, and from the script you send I see that this document
type has a location field, so that will just sort any product document that
matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**mart**ijnvg/document-**relationsbbuz20**13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

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

For more options, visit https://groups.google.com/**grou**ps/opt_outhttps://groups.google.com/groups/opt_out
.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

"RemoteTransportException[[Noble,
Peter][inet[/10.0.10.225:9300]][search/phase/query]]; nested:
QueryPhaseExecutionException[[testparentfacets][0]:
query[ChildrenQuery[product/group](custom score
(ConstantScore(:),function=script[doc[location].distance(40.6234,
-74.0288)], params [null]))],from[0],size[10]: Query Failed [failed to
execute context rewrite]]; nested: CompileException[[Error: No field found
for [org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints@34187f94]
in mapping with types ]\n[Near : {... doc[location].distance(40.6234
....}]\n ^\n[Line: 1, Column: 1]]; nested:
ElasticSearchIllegalArgumentException[No field found for
[org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints@34187f94] in
mapping with types ]; "

that does not work too

i attached file with my mapping and search query (look last query)

Are you sure it's supposed to work?

On Friday, September 6, 2013 3:23:57 AM UTC-4, Martijn v Groningen wrote:

You need to substitute the lat and long variables in the script with the
actual values:
"script": "doc['location'].distance(40.6234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev <m...@inetgiant.com <javascript:>>wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[Failed to execute phase
    [query_fetch], total failure; shardFailures
    {[8xa0yPbjREmk8DuC_jlipA][testparentfacets][0]:
    RemoteTransportException[[T-Ray][inet[/10.0.10.223:9301]][search/phase/query+fetch]];
    nested: QueryPhaseExecutionException[[testparentfacets][0]:
    query[ChildrenQuery[product/group](custom score
    (ConstantScore(:),function=script[doc['location'].distance(lat, lon)],
    params [null]))],from[0],size[10]: Query Failed [failed to execute
    context rewrite]]; nested: PropertyAccessException[[Error: unresolvable
    property or identifier: lat] [Near : {... doc['location'].distance(lat,
    lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen
wrote:

Did you see the last slide of the presentation I mentioned in my
previous reply?
What you need to do is move the sorting part to a custom_score query and
put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will see
two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen
wrote:

The query in the email doesn't use the has_child query, so I don't
know what you mean with sorting for childs. So in this case you're
searching for product documents, and from the script you send I see that
this document type has a location field, so that will just sort any product
document that matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**mart**ijnvg/document-**relationsbbuz20**13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

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

For more options, visit https://groups.google.com/**grou**ps/opt_outhttps://groups.google.com/groups/opt_out
.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

The reason this error occurred was because of quoting issue. This shouldn't
cause an error:
curl -XPOST 'localhost:9203/testparentfacets/_search?pretty=true' -d '{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234, -74.0288)"
}
}
}
}
}'

On 6 September 2013 13:40, Max Seleznev max@inetgiant.com wrote:

"RemoteTransportException[[Noble, Peter][inet[/10.0.10.225:9300]][search/phase/query]];
nested: QueryPhaseExecutionException[[testparentfacets][0]:
query[ChildrenQuery[product/group](custom score
(ConstantScore(:),function=script[doc[location].distance(40.6234,
-74.0288)], params [null]))],from[0],size[10]: Query Failed [failed to
execute context rewrite]]; nested: CompileException[[Error: No field found
for [org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints@34187f94]
in mapping with types ]\n[Near : {... doc[location].distance(40.6234
....}]\n ^\n[Line: 1, Column: 1]]; nested:
ElasticSearchIllegalArgumentException[No field found for
[org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints@34187f94] in
mapping with types ]; "

that does not work too

i attached file with my mapping and search query (look last query)

Are you sure it's supposed to work?

On Friday, September 6, 2013 3:23:57 AM UTC-4, Martijn v Groningen wrote:

You need to substitute the lat and long variables in the script with the
actual values:
"script": "doc['location'].distance(40.**6234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev m...@inetgiant.com wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[**Failed to execute phase
    [query_fetch], total failure; shardFailures {[8xa0yPbjREmk8DuC_jlipA][
    testparentfacets][0]: RemoteTransportException[[T-
    Ray][inet[/10.0.10.223:9301]][**search/phase/query+fetch]]; nested:
    QueryPhaseExecutionException[[**testparentfacets][0]:
    query[ChildrenQuery[product/**group](custom score
    (ConstantScore(:),function=**script[doc['location'].**distance(lat,
    lon)], params [null]))],from[0],size[10]: *Query Failed [failed to
    execute context rewrite]]; nested: PropertyAccessException[[Error:
    unresolvable property or identifier: lat] [Near : {...
    doc['location'].distance(lat, lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen
wrote:

Did you see the last slide of the presentation I mentioned in my
previous reply?
What you need to do is move the sorting part to a custom_score query
and put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will see
two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen
wrote:

The query in the email doesn't use the has_child query, so I don't
know what you mean with sorting for childs. So in this case you're
searching for product documents, and from the script you send I see that
this document type has a location field, so that will just sort any product
document that matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**mart****ijnvg/document-**relationsbbuz20*
***13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

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

For more options, visit https://groups.google.com/**grou****
ps/opt_out https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

thanks, but sort does not work

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234, -74.0288)"
}
}
}
}
}

result

"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",
"_score" : null, "_source" :
{"hash":"64a4c4d0cf3ab7bb17e0ba62e7e201cd"},
"sort" : [ 1.7976931348623157E308 ]
}, {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "24237bb1791edbfdf349f9ffcbcaea13",
"_score" : null, "_source" :
{"hash":"24237bb1791edbfdf349f9ffcbcaea13"},
"sort" : [ 1.7976931348623157E308 ]
} ]
}

On Friday, September 6, 2013 8:29:10 AM UTC-4, Martijn v Groningen wrote:

The reason this error occurred was because of quoting issue. This
shouldn't cause an error:
curl -XPOST 'localhost:9203/testparentfacets/_search?pretty=true' -d '{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234,
-74.0288)"
}
}
}
}
}'

On 6 September 2013 13:40, Max Seleznev <m...@inetgiant.com <javascript:>>wrote:

"RemoteTransportException[[Noble,
Peter][inet[/10.0.10.225:9300]][search/phase/query]]; nested:
QueryPhaseExecutionException[[testparentfacets][0]:
query[ChildrenQuery[product/group](custom score
(ConstantScore(:),function=script[doc[location].distance(40.6234,
-74.0288)], params [null]))],from[0],size[10]: Query Failed [failed to
execute context rewrite]]; nested: CompileException[[Error: No field found
for [org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints@34187f94]
in mapping with types ]\n[Near : {... doc[location].distance(40.6234
....}]\n ^\n[Line: 1, Column: 1]]; nested:
ElasticSearchIllegalArgumentException[No field found for
[org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints@34187f94] in
mapping with types ]; "

that does not work too

i attached file with my mapping and search query (look last query)

Are you sure it's supposed to work?

On Friday, September 6, 2013 3:23:57 AM UTC-4, Martijn v Groningen wrote:

You need to substitute the lat and long variables in the script with the
actual values:
"script": "doc['location'].distance(40.**6234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev m...@inetgiant.com wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[**Failed to execute phase
    [query_fetch], total failure; shardFailures {[8xa0yPbjREmk8DuC_jlipA][
    testparentfacets][0]: RemoteTransportException[[T-
    Ray][inet[/10.0.10.223:9301]][**search/phase/query+fetch]]; nested:
    QueryPhaseExecutionException[[**testparentfacets][0]:
    query[ChildrenQuery[product/**group](custom score
    (ConstantScore(:),function=**script[doc['location'].**distance(lat,
    lon)], params [null]))],from[0],size[10]: *Query Failed [failed to
    execute context rewrite]]; nested: PropertyAccessException[[Error:
    unresolvable property or identifier: lat] [Near : {...
    doc['location'].distance(lat, lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen
wrote:

Did you see the last slide of the presentation I mentioned in my
previous reply?
What you need to do is move the sorting part to a custom_score query
and put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will see
two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen
wrote:

The query in the email doesn't use the has_child query, so I don't
know what you mean with sorting for childs. So in this case you're
searching for product documents, and from the script you send I see that
this document type has a location field, so that will just sort any product
document that matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**mart****ijnvg/document-**relationsbbuz20
****13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.com wrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

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

For more options, visit https://groups.google.com/**grou****
ps/opt_out https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

The sorting by distance is done inside the script, you should remove the
other sort. The script will output the distance in the _score field for
each hit.

On 6 September 2013 14:38, Max Seleznev max@inetgiant.com wrote:

thanks, but sort does not work

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234,
-74.0288)"
}
}
}
}
}

result

"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",
"_score" : null, "_source" :
{"hash":"64a4c4d0cf3ab7bb17e0ba62e7e201cd"},
"sort" : [ 1.7976931348623157E308 ]
}, {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "24237bb1791edbfdf349f9ffcbcaea13",
"_score" : null, "_source" :
{"hash":"24237bb1791edbfdf349f9ffcbcaea13"},
"sort" : [ 1.7976931348623157E308 ]
} ]
}

On Friday, September 6, 2013 8:29:10 AM UTC-4, Martijn v Groningen wrote:

The reason this error occurred was because of quoting issue. This
shouldn't cause an error:
curl -XPOST 'localhost:9203/**testparentfacets/_search?**pretty=true' -d
'{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(**40.6234,
-74.0288)"
}
}
}
}
}'

On 6 September 2013 13:40, Max Seleznev m...@inetgiant.com wrote:

"RemoteTransportException[[Noble, Peter][inet[/10.0.10.225:9300]][search/phase/query]];
nested: QueryPhaseExecutionException[[**testparentfacets][0]:
query[ChildrenQuery[product/**group](custom score
(ConstantScore(:),function=**script[doc[location].distance(40.6234,
-74.0288)], params [null]))],from[0],size[10]: Query Failed [failed to
execute context rewrite]]; nested: CompileException[[Error: No field found
for [org.elasticsearch.index.fielddata.ScriptDocValues$
GeoPoints@34187f94] in mapping with types []]\n[Near : {...
doc[location].distance(40.6234 ....}]\n ^\n[Line: 1, Column:
1]]; nested: ElasticSearchIllegalArgumentEx
ception[No field found for
[org.elasticsearch.index.fielddata.ScriptDocValues$
GeoPoints@34187f94] in mapping with types ]; "

that does not work too

i attached file with my mapping and search query (look last query)

Are you sure it's supposed to work?

On Friday, September 6, 2013 3:23:57 AM UTC-4, Martijn v Groningen wrote:

You need to substitute the lat and long variables in the script with
the actual values:
"script": "doc['location'].distance(40.6234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev m...@inetgiant.com wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[****Failed to execute phase
    [query_fetch], total failure; shardFailures {[8xa0yPbjREmk8DuC_jlipA][
    testparentfacets][0]: RemoteTransportException[[T-Ra
    y][inet[/10.0.10.223:9301]][search/phase/query+fetch]];
    nested: QueryPhaseExecutionException[[**testparentfacets][0]:
    query[ChildrenQuery[product/group](custom score
    (ConstantScore(
    :
    ),function=script[doc['location'].*distance
    *(lat, lon)], params [null]))],from[0],size[10]: *Query Failed
    [failed to execute context rewrite]]; nested: PropertyAccessException[[
    Error: unresolvable property or identifier: lat] [Near : {...
    doc['location'].distance(lat, lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen
wrote:

Did you see the last slide of the presentation I mentioned in my
previous reply?
What you need to do is move the sorting part to a custom_score query
and put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by the
distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will
see two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v Groningen
wrote:

The query in the email doesn't use the has_child query, so I don't
know what you mean with sorting for childs. So in this case you're
searching for product documents, and from the script you send I see that
this document type has a location field, so that will just sort any product
document that matches.

Sorting parent document by fields that are in child documents isn't
supported. There is a work around that uses the custom_score query in the
has_child query, that allows you to psuedo sort parent document by fields
in child docs:
http://www.slideshare.net/**mart******ijnvg/document-**
relationsbbuz20******13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.comwrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

--
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.**c****om.

For more options, visit https://groups.google.com/**grou******
ps/opt_out https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

That does not work,
full script es.geo.sort.sh · GitHub

item 1

parent

{"ok":true,"_index":"testparentfacets","_type":"group","_id":"*
64a4c4d0cf3ab7bb17e0ba62e7e201cd*","_version":1}

child

{"ok":true,"_index":"testparentfacets","_type":"product","_id":"*
bca1efe0cd89dc42bfc913f098b67bf3*","_version":1}
item 2

parent

{"ok":true,"_index":"testparentfacets","_type":"group","_id":"*
24237bb1791edbfdf349f9ffcbcaea13*","_version":1}

child

{"ok":true,"_index":"testparentfacets","_type":"product","_id":"*
f047b7225daa8dd2ab6258f9fed9a3e1*","_version":1}

this is result with not correct sort, i run search query by parect and
sort by location (first query)
not good results

{

"took" : 2,

"timed_out" : false,

"_shards" : {

"total" : 2,

"successful" : 2,

"failed" : 0

},

"hits" : {

"total" : 2,

"max_score" : null,

"hits" : [ {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",

"_score" : null,

"sort" : [ 1.7976931348623157E308 ]

}, {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "24237bb1791edbfdf349f9ffcbcaea13",

"_score" : null,

"sort" : [ 1.7976931348623157E308 ]

} ]

}

}

this is result with correct sort, i run search query by childs only and
sort by location (second query)
perfect results

{

"took" : 1,

"timed_out" : false,

"_shards" : {

"total" : 2,

"successful" : 2,

"failed" : 0

},

"hits" : {

"total" : 2,

"max_score" : null,

"hits" : [ {

"_index" : "testparentfacets",

"_type" : "product",

"_id" : "f047b7225daa8dd2ab6258f9fed9a3e1",

                                    *parent* *

24237bb1791edbfdf349f9ffcbcaea13*

"_score" : null,

"sort" : [ 50.236949738919485 ]

}, {

"_index" : "testparentfacets",

"_type" : "product",

"_id" : "bca1efe0cd89dc42bfc913f098b67bf3",

                                     *parent* *

64a4c4d0cf3ab7bb17e0ba62e7e201cd*

"_score" : null,

"sort" : [ 56.1165820505235 ]

} ]

}

}

and your example, result is not correct

curl -XPOST 'http://10.0.10.223:9200/testparentfacets/_search?pretty=true'
-d '
{
"fields": ,
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234, -74.0288)"
}
}
}
}
}

' && echo

{

"took" : 2,

"timed_out" : false,

"_shards" : {

"total" : 5,

"successful" : 5,

"failed" : 0

},

"hits" : {

"total" : 2,

"max_score" : 39.39948,

"hits" : [ {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",

"_score" : 39.39948

}, {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "24237bb1791edbfdf349f9ffcbcaea13",

"_score" : 33.126003

} ]

}

}

On Friday, September 6, 2013 9:06:46 AM UTC-4, Martijn v Groningen wrote:

The sorting by distance is done inside the script, you should remove the
other sort. The script will output the distance in the _score field for
each hit.

On 6 September 2013 14:38, Max Seleznev <m...@inetgiant.com <javascript:>>wrote:

thanks, but sort does not work

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234,
-74.0288)"
}
}
}
}
}

result

"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",
"_score" : null, "_source" :
{"hash":"64a4c4d0cf3ab7bb17e0ba62e7e201cd"},
"sort" : [ 1.7976931348623157E308 ]
}, {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "24237bb1791edbfdf349f9ffcbcaea13",
"_score" : null, "_source" :
{"hash":"24237bb1791edbfdf349f9ffcbcaea13"},
"sort" : [ 1.7976931348623157E308 ]
} ]
}

On Friday, September 6, 2013 8:29:10 AM UTC-4, Martijn v Groningen wrote:

The reason this error occurred was because of quoting issue. This
shouldn't cause an error:
curl -XPOST 'localhost:9203/**testparentfacets/_search?**pretty=true'
-d '{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(**40.6234,
-74.0288)"
}
}
}
}
}'

On 6 September 2013 13:40, Max Seleznev m...@inetgiant.com wrote:

"RemoteTransportException[[Noble, Peter][inet[/10.0.10.225:9300]][search/phase/query]];
nested: QueryPhaseExecutionException[[**testparentfacets][0]:
query[ChildrenQuery[product/**group](custom score
(ConstantScore(:),function=**script[doc[location].distance(**40.6234,
-74.0288)], params [null]))],from[0],size[10]: Query Failed [failed to
execute context rewrite]]; nested: CompileException[[Error: No field found
for [org.elasticsearch.index.**fielddata.ScriptDocValues$GeoPoints@34187f94]
in mapping with types []]\n[Near : {... doc[location].distance(40.6234
....}]\n ^\n[Line: 1, Column: 1]]; nested:
ElasticSearchIllegalArgumentEx
ception[No field found for
[org.elasticsearch.index.**fielddata.ScriptDocValues$**GeoPoints@34187f94]
in mapping with types ]; "

that does not work too

i attached file with my mapping and search query (look last query)

Are you sure it's supposed to work?

On Friday, September 6, 2013 3:23:57 AM UTC-4, Martijn v Groningen
wrote:

You need to substitute the lat and long variables in the script with
the actual values:
"script": "doc['location'].distance(40.6234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev m...@inetgiant.com wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[****Failed to execute
    phase [query_fetch], total failure; shardFailures {[8xa0yPbjREmk8DuC_jlipA][
    testparentfacets][0]: RemoteTransportException[[T-Ra
    y][inet[/10.0.10.223:9301]][search/phase/query+fetch]];
    nested: QueryPhaseExecutionException[[**testparentfacets][0]:
    query[ChildrenQuery[product/group](custom score
    (ConstantScore(
    :
    ),function=script[doc['location'].**distance
    **(lat, lon)], params [null]))],from[0],size[10]: *Query Failed
    [failed to execute context rewrite]]; nested: PropertyAccessException[[
    Error: unresolvable property or identifier: lat] [Near : {...
    doc['location'].distance(lat, lon) ....}] ^ [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen
wrote:

Did you see the last slide of the presentation I mentioned in my
previous reply?
What you need to do is move the sorting part to a custom_score query
and put that in the has_child query as inner query. Something like this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by
the distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will
see two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v
Groningen wrote:

The query in the email doesn't use the has_child query, so I don't
know what you mean with sorting for childs. So in this case you're
searching for product documents, and from the script you send I see that
this document type has a location field, so that will just sort any product
document that matches.

Sorting parent document by fields that are in child documents
isn't supported. There is a work around that uses the custom_score query in
the has_child query, that allows you to psuedo sort parent document by
fields in child docs:
http://www.slideshare.net/**mart******ijnvg/document-**
relationsbbuz20******13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.comwrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is not
correctly specified in the sorting, but how to specify the correctly for
sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

--
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.**c****om.

For more options, visit https://groups.google.com/**grou******
ps/opt_out https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Like I mentioned in my first reply this is a work around and it isn't
perfect. You're sorting now by score, so the computed distance gets
transformed from a double into a float value (so its losses precision). I
forgot the mention that you're sorting in descending order, if you want to
sort in ascending order you need to change the script to this:
"-doc["location"].distance(40.6234, -74.0288)"

Also the distance right now is computed in miles, if you want the use km as
unit then you need to use the 'distanceInKm' function:
"-doc["location"]. distanceInKm(40.6234, -74.0288)"

I think it makes sense if you use the 'round' function in order to minimize
the double to float conversion error. More information about scripts and
functions:

On 6 September 2013 17:07, Max Seleznev max@inetgiant.com wrote:

That does not work,
full script es.geo.sort.sh · GitHub

item 1

parent

{"ok":true,"_index":"testparentfacets","_type":"group","_id":"*
64a4c4d0cf3ab7bb17e0ba62e7e201cd*","_version":1}

child

{"ok":true,"_index":"testparentfacets","_type":"product","_id":"*
bca1efe0cd89dc42bfc913f098b67bf3*","_version":1}
item 2

parent

{"ok":true,"_index":"testparentfacets","_type":"group","_id":"*
24237bb1791edbfdf349f9ffcbcaea13*","_version":1}

child

{"ok":true,"_index":"testparentfacets","_type":"product","_id":"*
f047b7225daa8dd2ab6258f9fed9a3e1*","_version":1}

this is result with not correct sort, i run search query by parect and
sort by location (first query)
not good results

{

"took" : 2,

"timed_out" : false,

"_shards" : {

"total" : 2,

"successful" : 2,

"failed" : 0

},

"hits" : {

"total" : 2,

"max_score" : null,

"hits" : [ {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",

"_score" : null,

"sort" : [ 1.7976931348623157E308 ]

}, {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "24237bb1791edbfdf349f9ffcbcaea13",

"_score" : null,

"sort" : [ 1.7976931348623157E308 ]

} ]

}

}

this is result with correct sort, i run search query by childs only and
sort by location (second query)
perfect results

{

"took" : 1,

"timed_out" : false,

"_shards" : {

"total" : 2,

"successful" : 2,

"failed" : 0

},

"hits" : {

"total" : 2,

"max_score" : null,

"hits" : [ {

"_index" : "testparentfacets",

"_type" : "product",

"_id" : "f047b7225daa8dd2ab6258f9fed9a3e1",

                                      *parent* *

24237bb1791edbfdf349f9ffcbcaea13*

"_score" : null,

"sort" : [ 50.236949738919485 ]

}, {

"_index" : "testparentfacets",

"_type" : "product",

"_id" : "bca1efe0cd89dc42bfc913f098b67bf3",

                                       *parent* *

64a4c4d0cf3ab7bb17e0ba62e7e201cd*

"_score" : null,

"sort" : [ 56.1165820505235 ]

} ]

}

}

and your example, result is not correct

curl -XPOST 'http://10.0.10.223:9200/testparentfacets/_search?pretty=true'
-d '
{
"fields": ,
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234, -74.0288)"
}
}
}
}
}

' && echo

{

"took" : 2,

"timed_out" : false,

"_shards" : {

"total" : 5,

"successful" : 5,

"failed" : 0

},

"hits" : {

"total" : 2,

"max_score" : 39.39948,

"hits" : [ {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",

"_score" : 39.39948

}, {

"_index" : "testparentfacets",

"_type" : "group",

"_id" : "24237bb1791edbfdf349f9ffcbcaea13",

"_score" : 33.126003

} ]

}

}

On Friday, September 6, 2013 9:06:46 AM UTC-4, Martijn v Groningen wrote:

The sorting by distance is done inside the script, you should remove the
other sort. The script will output the distance in the _score field for
each hit.

On 6 September 2013 14:38, Max Seleznev m...@inetgiant.com wrote:

thanks, but sort does not work

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(**40.6234,
-74.0288)"
}
}
}
}
}

result

"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "64a4c4d0cf3ab7bb17e0ba62e7e201cd",
"_score" : null, "_source" : {"hash":"**
64a4c4d0cf3ab7bb17e0ba62e7e201cd"},
"sort" : [ 1.7976931348623157E308 ]
}, {
"_index" : "testparentfacets",
"_type" : "group",
"_id" : "24237bb1791edbfdf349f9ffcbcaea13",
"_score" : null, "_source" : {"hash":"

24237bb1791edbfdf349f9ffcbcaea**13"},
"sort" : [ 1.7976931348623157E308 ]
} ]
}

On Friday, September 6, 2013 8:29:10 AM UTC-4, Martijn v Groningen wrote:

The reason this error occurred was because of quoting issue. This
shouldn't cause an error:
curl -XPOST 'localhost:9203/testparentfacets/_search?**pretty=true'
-d '{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc["location"].distance(40.6234,
-74.0288)"
}
}
}
}
}'

On 6 September 2013 13:40, Max Seleznev m...@inetgiant.com wrote:

"RemoteTransportException[[Noble, Peter][inet[/10.0.10.225:9300]**
**][search/phase/query]]; nested: QueryPhaseExecutionException[[testparentfacets][0]:
query[ChildrenQuery[product/group](custom score
(ConstantScore(
:
),function=script[doc[location].distance(40.6234,
-74.0288)], params [null]))],from[0],size[10]: Query Failed [failed to
execute context rewrite]]; nested: CompileException[[Error: No field found
for [org.elasticsearch.index.fielddata.ScriptDocValues$**GeoPoints
**@34187f94] in mapping with types []]\n[Near : {...
doc[location].distance(40.6234 ....}]\n ^\n[Line: 1, Column:
1]]; nested: ElasticSearchIllegalArgumentEx
**ception[No field found
for [org.elasticsearch.index.fielddata.ScriptDocValues$**GeoPoints
**@34187f94] in mapping with types ]; "

that does not work too

i attached file with my mapping and search query (look last query)

Are you sure it's supposed to work?

On Friday, September 6, 2013 3:23:57 AM UTC-4, Martijn v Groningen
wrote:

You need to substitute the lat and long variables in the script with
the actual values:
"script": "doc['location'].distance(40.**6****234, -74.0288)"

On 5 September 2013 21:16, Max Seleznev m...@inetgiant.com wrote:

Thanks for idea, but i run your example and have error

  • error: SearchPhaseExecutionException[Failed to execute
    phase [query_fetch], total failure; shardFailures {[8xa0yPbjREmk8DuC_jlipA][
    **test
    parentfacets][0]: RemoteTransportException[[T-Ra

    y][inet[/10.0.10.223:9301]][search/phase/query+fetch]];
    nested: QueryPhaseExecutionException[[testparentfacets][0]:
    query[ChildrenQuery[product/**gr
    oup](custom score
    (ConstantScore(
    :
    ),function=**s
    cript[doc['location'].

    distance****(lat, lon)], params [null]))],from[0],size[10]: Query
    Failed [failed to execute context rewrite]]; nested:
    PropertyAccessException[[Error: unresolvable property or
    identifier: lat] [Near : {... doc['location'].distance(lat, lon) ....}] ^
    [Line: 1, Column: 26]]; }]
  • status: 500

On Thursday, September 5, 2013 1:21:16 PM UTC-4, Martijn v Groningen
wrote:

Did you see the last slide of the presentation I mentioned in my
previous reply?
What you need to do is move the sorting part to a custom_score
query and put that in the has_child query as inner query. Something like
this:
{
"query": {
"has_child": {
"score_type": "max",
"type": "product",
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"script": "doc['location'].distance(lat, lon)"
}
}
}
}
}

In the above example the sorting by distance has been replaced by
the distance function in the script.

On 5 September 2013 16:29, Max Seleznev m...@inetgiant.com wrote:

sorry, I mixed queries.
I attached file with the request, if you started it then you will
see two requests
can you run attached file
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {

  • "has_child": {*
    "score_type": "max",
    "type": "product",
    "query": {
    "custom_filters_score": {
    "query": {
    "filtered": {
    "query": {
    "bool": {
    "must": [
    {
    "multi_match": {
    "query": "Infiniti",
    "fields": [
    "title",
    "description",
    "facets",
    "keywords",
    "categories",
    "hidden"
    ],
    "operator": "and",
    "use_dis_max": false
    }
    }
    ],
    "should":
    }
    },
    "filter": {
    "and": [
    {
    "bool": {
    "must": [
    {
    "terms": {
    "base_topic": [
    "1",
    "2",
    "597820",
    "599660",
    "599661",
    "5256322",
    "599666",
    "1753836",
    "599667",
    "599669",
    "5240682",
    "599662",
    "5240666",
    "599668",
    "5240672",
    "5326625",
    "5256324",
    "599663",
    "5240669",
    "599665",
    "1753835"
    ]
    }
    },
    {
    "term": {
    "id_country": 1
    }
    },
    {
    "range": {
    "date": {
    "from": 1376938800
    }
    }
    }
    ]
    }
    },
    {
    "or": [
    {
    "geo_distance": {
    "distance": "100km",
    "location": {
    "lat": 40.6234,
    "lon": -74.0288
    }
    }
    },
    {
    "missing": {
    "field": "location"
    }
    }
    ]
    }
    ]
    }
    }
    },
    "filters": ,
    "score_mode": "total"
    }
    }
    }
    },
    "from": 0,
    "size": 60
    }

On Thursday, September 5, 2013 8:52:51 AM UTC-4, Martijn v
Groningen wrote:

The query in the email doesn't use the has_child query, so I
don't know what you mean with sorting for childs. So in this case you're
searching for product documents, and from the script you send I see that
this document type has a location field, so that will just sort any product
document that matches.

Sorting parent document by fields that are in child documents
isn't supported. There is a work around that uses the custom_score query in
the has_child query, that allows you to psuedo sort parent document by
fields in child docs:
http://www.slideshare.net/**mart********ijnvg/document-**
relationsbbuz20********13http://www.slideshare.net/martijnvg/document-relationsbbuz2013(last slide)

On 4 September 2013 23:06, Max Seleznev m...@inetgiant.comwrote:

can you help me, how i can use correct sort for childs
i have query but sort does not work, I know that the field is
not correctly specified in the sorting, but how to specify the correctly
for sorting for childs

{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 40.6234,
"lon": -74.0288
},
"order": "asc",
"unit": "km"
}
}
],
"fields": ,
"query": {
"custom_filters_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Infiniti",
"fields": [
"title",
"description",
"facets",
"keywords",
"categories",
"hidden"
],
"operator": "and",
"use_dis_max": false
}
}
],
"should":
}
},
"filter": {
"and": [
{
"bool": {
"must": [
{
"terms": {
"base_topic": [
"1",
"2",
"597820",
"599660",
"599661",
"5256322",
"599666",
"1753836",
"599667",
"599669",
"5240682",
"599662",
"5240666",
"599668",
"5240672",
"5326625",
"5256324",
"599663",
"5240669",
"599665",
"1753835"
]
}
},
{
"term": {
"id_country": 1
}
},
{
"range": {
"date": {
"from": 1376938800
}
}
}
]
}
},
{
"or": [
{
"geo_distance": {
"distance": "100km",
"location": {
"lat": 40.6234,
"lon": -74.0288
}
}
},
{
"missing": {
"field": "location"
}
}
]
}
]
}
}
},
"filters": ,
"score_mode": "total"
}
},
"from": 0,
"size": 60
}

--
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.c**om.

For more options, visit https://groups.google.com/**grou********
ps/opt_out https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.