Is it possible to assign a query to a variable?

HI All,

I have created an index and my basic query starts:

GET kmnewindex/_search
{
  "query": { "query_string": {"query": "going home", "fields": ["squestion", "ssubject"]}
},
  "_source": ["idisid", "itopid" ,"ipid", "ssubject", "dcreated", "squestion", "suserhrid","suserfname","susersname","stopname"]
}

I want to expand on this search, but don't think that parent/child relationship or span will do what I want.

In SQL my next step would be:

SELECT x.idisid, x.ipid
	FROM kmnewindex x
	WHERE x.ipid= 0

	UNION ALL

	SELECT MIN(y.idisid) AS idisid, y.ipid
	FROM kmnewindex y
	GROUP BY y.ipid
	HAVING NOT y.ipid= 0

Then I want to return all from the original query where idisid from my second query isn't in the original set where its equal to ipid.

SO what I really want to do is store the first and second query in variables then use both in a new query.

Hi,
without knowing what your use case looks like its a bit hard to understand what the SQL is doing, but generally I would start to look into using one of the many language clients if you want to do something that needs results from one query to construct a second one (e.g. joins in relational databases). This usually means you execute one or more queries, then process the results (e.g. combining on some key etc...) and then use those in a final query. While you might to cram some of what you are doing in the SQL into a single query, its often less complex (and probably not much slower) to do so in two steps.
Hope this helps to get started.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.