Here it is stated in nested documents, without using nested query it is not possible to retrieve document which satisfies multiple conditions at the same time through nested document's fields. Here also another explanation with example at beginning. Why does not it retrieve the only doc which satisfies all conditions?
if you need multiple conditions with nested queries, why not to use bool query or bool filtered query?
Related
We want to have a solution to compare a nested key value with root level field. Can we access a nested key value for filter(script)? We can get value from script field(parms), but we can't use parms in filter function. Only doc can be used from my knowledge, but doc in filter script we can't access nested structure. If doc under nested path, the meanwhile we can't access root level field.
You could leverage the copy_to / include_in_root parameters in order to allow _source access in a script, as I've outlined in my answer to How to iterate through a nested array in elasticsearch with filter script?
Alternatively, you could hijack a function_score query which, unlike standard filters, still has access to params._source without any mapping adjustments. Discussed in more detail in this thread.
Im tring to understand the DSL query i needed if i want to make a search from a result set i got. means i have an initial term search, then i want make another query upon the previous result.
lets say i a have 10 documents with a sharing identifier between them, each document has a description field. i want to search first all the documents containing the value 'Hello' in the description and then take their id's, and search the document containing the value 'good by'.
thanks.
No need to execute two queries, you can use filter context that will filter out the results.filter parameter will filter out documents that do not match, and will also not affect the score for matching documents.
Filter context is in effect whenever a query clause is passed to a
filter parameter, such as the filter or must_not parameters in the
bool query, the filter parameter in the constant_score query, or the
filter aggregation.
Refer this to know more about Query and Filter contexts
Good day:
I'm currently have the following structure indexed school -> children...meaning for every school document, there's a list of children sub documents. Children is a nested list of objects inside School. My objective is to query the parent school.id=id and only return the sub-documents matching children.userId = userId while paginating the children size/from. I'm not sure how to accomplish this but, any help using NEST would be appreciated.
Thanks.
EDIT:
I didn't realize you only wanted to paginate the results from a single document. In that case you can use inner_hits which has it's own from and size parameters you can use.
Reference: inner_hits documentation
ORIGINAL ANSWER:
I don't think you can paginate directly on the inner object when you have a nested type. Instead you would want to index school and children in separate documents and use a join type to create a parent/child relationship between them. Then you could use a has_parent query to search for children and paginate on the children returned.
Reference:
How to create the mapping: Join Relationship
How to create the query: has_parent query
Is there a way in ElasticSearch wherein I can remove some the objects in the nested field array.
So I have a nested field and it returns array of objects. I need to remove some objects in the nested field.
Is it possible to do so in the query or I need to do that in my code
These extra nested documents are hidden; we can’t access them directly. To update, add, or remove a nested object, we have to reindex the whole document. It’s important to note that, the result returned by a search request is not the nested object alone; it is the whole document.
Nested Objects Elastic search
As far as I know, In Elasticsearch you can't just remove part of a existing document. You should change the document (remove objects you don't need) and renew(rewrite) the document.
In Elasticsearch, is there any way to exclude the nested objects that don't match a particular query/filter from the resulting _source?
For example, let's say that a document has four objects in a nested field. Querying on the required filters results in only matching objects 1 and 3. When we get the results via _source, we will pull back the entire document along with objects 1,2,3,4.
Is it possible to exclude objects 2 and 4 from the results? Or is that something that we have to re-iterate and exclude using application-side logic?
At the moment there is no way to include only the matched nested objects in the result.
There is a inner_hits feature coming out in elasticsearch 1.5.0 which should help with this.
You can achieve this with use of inner_hits which will return you only matching nested objects. you can exclude this nested field in source.
Suggested by Val at:
ElasticSearch - Get only matching nested objects with All Top level fields in search response