Search query based on the document's different field value's comparison


(narinder.izap) #1

Hi Shay,
Can you please guide me to the following problem, suppose i am
having the following document structure,

{
"name":"narinder",
"guid" : "345435",
"parent_guid": "544333",
"country_guid": "456778",
"current_location_guid":"765432"
}

Here I want to search all the document, where country_guid ==
current_location_guid, and same kind of search on string fields too. Is it
implemented in elasticsearch??


(narinder.izap) #2

and more over I need to add the higher priority on such case too using
custom_filter_score query, if its possible in elasticsearch, please help me
in the syntax too,

Thank you
Narinder Kaur

On Tuesday, 10 July 2012 12:57:11 UTC+5:30, Narinder Kaur wrote:

Hi Shay,
Can you please guide me to the following problem, suppose i am
having the following document structure,

{
"name":"narinder",
"guid" : "345435",
"parent_guid": "544333",
"country_guid": "456778",
"current_location_guid":"765432"
}

Here I want to search all the document, where country_guid ==
current_location_guid, and same kind of search on string fields too. Is it
implemented in elasticsearch??


(Shaun Etherton) #3

Hello

Perhaps you could do something like the following?

"filtered" : {
"query" : {
...
},
"filter" : {
"script" : {
"script" : "doc['country_guid'].value == doc['current_location_guid'].value"
}
}
}

http://www.elasticsearch.org/guide/reference/query-dsl/script-filter.html

HTH.

  • shaun

--
shaun etherton
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Tuesday, 10 July 2012 at 4:57 PM, Narinder Kaur wrote:

Hi Shay,
Can you please guide me to the following problem, suppose i am having the following document structure,

{
"name":"narinder",
"guid" : "345435",
"parent_guid": "544333",
"country_guid": "456778",
"current_location_guid":"765432"
}

Here I want to search all the document, where country_guid == current_location_guid, and same kind of search on string fields too. Is it implemented in elasticsearch??


(narinder.izap) #4

thank you, it will be really helpful.

On Tuesday, 10 July 2012 18:21:34 UTC+5:30, Shaun Etherton wrote:

Hello

Perhaps you could do something like the following?

"filtered" : {
"query" : {
...
},
"filter" : {
"script" : {
"script" : "doc['country_guid'].value ==
doc['current_location_guid'].value"
}
}
}

http://www.elasticsearch.org/guide/reference/query-dsl/script-filter.html

HTH.

  • shaun

--
shaun etherton
Sent with Sparrow http://www.sparrowmailapp.com/?sig

On Tuesday, 10 July 2012 at 4:57 PM, Narinder Kaur wrote:

Hi Shay,
Can you please guide me to the following problem, suppose i am
having the following document structure,

{
"name":"narinder",
"guid" : "345435",
"parent_guid": "544333",
"country_guid": "456778",
"current_location_guid":"765432"
}

Here I want to search all the document, where country_guid ==
current_location_guid, and same kind of search on string fields too. Is it
implemented in elasticsearch??


(system) #5