(java api) Filter out fields using setFetchSource based on their value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
ajs
Reply | Threaded
Open this post in threaded view
|

(java api) Filter out fields using setFetchSource based on their value

ajs
This post has NOT been accepted by the mailing list yet.
Hi,

I have a document structure like
{
	"properties": {
		"name": "demo doc",
		"types": [
			{
				"type":"A",
				"name":"a demo"
			},
			{
				"type":"B",
				"name":"b demo"
			},
			{
				"type":"X",
				"name":"x demo"
			}
		]
	}
}

Now when doing a query I need to filter out the array item "x demo" as it has a type of X (it depends on the permissions of the user logged in what type to filter out - another user might only be able to view type X without A,B.

Is this possible using the setFetchSource filter? Is there another pre-processing possible?

I tried walking though the SearchHits.getHits and change the items getFields() before returning the list - this worked if I accessed the HitResult getSource() properties directly, but doing a getSourceAsString() still returned the original properties.

Thanks,
ajs