I am new to elastic search.
How do I write a query like below
Select count(1)c , status_code
From
Index-b2b-api
Where api-proxy-name = 'some-b2b-api'
Group by status_code
Thanks
Related
In SQL, we can perform the following in the where clause:
SELECT * FROM tbl WHERE :parameter <> '' OR :parameter is not null
Is this possible in elastic search to check if the input parameter/value is not null or empty? I checked the exists query but the parameter is a field, not a value.
You can use SQL API or using Exists Query.
Ex:
POST /_sql?format=txt
{
"query": "SELECT * FROM bar WHERE Id <> '' AND Id is not null"
}
In ElasticSearch using aggs you can easily replicate this sql query
SELECT COUNT(id) FROM table;
But I want this:
SELECT COUNT(id), id FROM table;
Or even better I want to do:
SELECT COUNT(price) * price FROM table;
Is this even possible in Elasticsearch?
I have tried “terms” and similar , using pipelines or bucket_script BUT the problem is doc_count is not accessible in buckets_path .
I begin to work with the Canvas section in Kibana - and to retrieve data, it uses Elasticsearch SQL.
What I try to do is to retrieve the count of several values ; and I need to group certain values together - the ones that start with the same letters.
My SQL query looks like this :
SELECT
(SELECT COUNT(*) FROM logs WHERE status LIKE 'missingValue%'),
(SELECT COUNT(*) FROM logs WHERE status LIKE 'errorValue%'),
(SELECT COUNT(*) FROM logs WHERE status='exactErrorValue'),
(SELECT COUNT(*) FROM logs WHERE status='anotherExactErrorValue')
When I test this query, using SQL and a little database, it works
Now, I want to make this work inside an element of my canvas. I choose a horizontal bar chart to represent it.
This is my elasticsearch SQL query :
SELECT
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status LIKE 'missingValue%'),
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status LIKE 'errorValue%'),
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status='exactErrorValue'),
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status='anotherExactErrorValue')
And I get this error :
{
"error": {
"message": "[essql] > Unexpected error from Elasticsearch: [unresolved_exception] Invalid call to nullable on an unresolved object ScalarSubquery[With[{}]
\\_Project[[?COUNT(?*)]]
\\_Filter[(status) REGEX (LikePattern)#5139]
\\_UnresolvedRelation[[][index=monitoring-func-*],null,Unknown index [monitoring-func-*]],5142] AS ?"
}
}
Seeing "unknown Index", I first thought that the wildcard was the problem.
But it's not, it's perfectly fine in my others Elasticsearch queries.
Is there something about the Subqueries, the multiple SELECT, that Elasticsearch SQL doesn't handle well ?
I didn't find any ressource or topics on this, but maybe I've searched the wrong way.
Depending on your Elasticsearch version, essql either doesn't support subqueries or it is very limited, here is the documentation.
I am unable to select the rows where TestId is max for respective student, I wrote the code as follows which does not get the required output. my code is as follows,
Criteria c = sessionFactory.getCurrentSession().createCriteria(student.class).setProjection(Projections.projectionList().add(Projections.property("answer"),"answer"));
c.add(Restrictions.eq("surveyId",send_Survey));
//c.add(Restrictions.eq("testId", "1" ));
//c.setProjection(Projection.max("testId"));
c.addOrder(Order.desc("testId"));
c.add(Restrictions.eq("questionid",FinalQuestionsOne));
List<String> age=c.list();
My table structure is as follows,
I need the following output. select the answer column for max TestId's. How can I get the output using criteria query
So I think what you're trying to get can be achievedd by the following sql:
SELECT TestId, MAX(answer) WHERE questionId = 1 GROUP BY TestId;
You should be able to achieve this with the following Hibernate:
sessionFactory.getCurrentSession().createCriteria(student.class).setProjection(Projections.projectionList()
.add(Projections.property("TestId"), "TestId")
.add(Projections.groupProperty("TestId"))
.add(Projections.max("answer")));
I would like to know how I can return the activity Id to a parent query using a query like the following to de-duplicate the parent record set. The issue here is that using this group by or distinct I cannot find a way.
I will use all of the group by fields to determine a unique record. But, I need to use only the record with the select min(status.effective_date)
The query returns the correct date values, but I cannot link it back to the parents activity records with just that date value.
select min(status.effective_date)
from accounts
, address
, activity
, status
where accounts.par_row_id = activity.account_id
and address.row_id = activity.address_id
and status.par_row_id = activity.status_id
and account.name = 'xyz'
group by account.name, address.addr, address.ADDR_LINE_2, address.ADDR_LINE_3
, address.ADDR_LINE_4, address.CITY, address.COUNTRY, address.X_STATE
, address.ZIPCODE
You should try this query:
select min(activity.row_id) keep(dense_rank first order by status.effective_date) as activity_id
from accounts
, address
, activity
, status
where accounts.par_row_id = activity.account_id
and address.row_id = activity.address_id
and status.par_row_id = activity.status_id
and accounts.name = 'xyz'
group by accounts.name, address.addr, address.ADDR_LINE_2, address.ADDR_LINE_3
, address.addr_line_4, address.city, address.country, address.x_state
, address.ZIPCODE;