I have to filter on a word in log.file.path. It works when I use a full string like this:
{
"query": {
"regexp": {
"log.file.path": "/Logs/APP/Business_TracingPerformance.POOL-16.txt"
}
}
}
But when I use a wildcard, nothing come out anymore
{
"query": {
"regexp": {
"log.file.path": "/Logs/APP/Business_TracingPerformance.*.txt"
}
}
}
Is there a reason why it doesn't work?
Related
I have a reusable block and I am trying to return it's dynamicContent using the following query. I am using the blocks id
{
reusableBlock(id: "10061756", idType: DATABASE_ID) {
blocks {
dynamicContent
saveContent
}
}
}
I am just getting null back no matter what I try
{
"data": {
"reusableBlock": null
},
"extensions": {
"debug": []
}
}
If I query a page where the block is, it works fine.
Is my query wrong or what am I missing?
I have a query like this:
query getUsers ($setId: Int) {
user(where: { user_sets: { set_id: { _in: [$setId] } } }) {
id
name
status
user_sets {
set {
name
}
}
# more fields...
}
}
What I'm looking for, is a way to not apply the where filter and give all entries if $setId is null. I'd like to avoid dynamically writing the query - it'd be easy to do something like this, but we want queries in static .graphql files:
const query = `
query getUsers (${ setId ? '$setId: Int' : ''}) {
user(${ setId ? 'where: { user_sets: { set_id: { _in: [$setId] } } }' : '' }) {
`
Some things I've tried:
Using GraphQL directives like #skip and #include, but it seems these only apply to fields returned, not to any part of a where filter
Using Hasura boolExps like _is_null and _or, but it seems these can't test variables directly, they can only compare variables to columns contents
This behaviour changed somewhere between v1.3.4. Therefore there are two correct answers.
You can read more about this change in the hasura repository.
Before Version 1.3.4
This answer describes it.
After Version 1.3.4
Using null in comparisons is dangerous when defaulting to true because an accidentally unset variable could result in a dropped table. The maintainers removed this behaviour but made it accessible by setting the variable HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE.
When comparing with {_eq: null}, Hasura will throw an error because it is assumed that this is a mistake.
If you want to compare to a value and evaluate to true when the value is null, you need to handle the case on the client side and pass the whole boolean expression to Hasura.
query getUsers ($userSetsWhere: user_sets_bool_exp) {
user(where: { user_sets: { $userSetsWhere } }) {
id
name
status
user_sets {
set {
name
}
}
# more fields...
}
}
const userSetsWhere = setId ? { set_id: { _eq: $setId } } : {};
What it does, is that only in case the value is not null or undefined a non-empty expression gets passed to Hasura.
You can use bool expressions as binding variables for such situations
query getUsers ($condition: user_bool_exp!) {
user (where: $condition) {
id
name
status
user_sets {
set {
name
}
}
# more fields...
}
}
And you can build conditions depending on your variables
{ condition: { user_sets: { set_id: { _in: [$setId] } } } }
or
{ condition: { user_sets: {} }
This answer only applies to Hasura v1.X, see other answers for more recent versions.
It seems like matching all if the variable is null is the default behaviour if the _eq boolExp is used. I wasn't seeing this because this query was using _in.
Changing to this gives all items if $setId is passed as null:
query getUsers ($setId: Int) {
user(where: { user_sets: { set_id: { _eq: $setId } } }) {
id
name
status
user_sets {
set {
name
}
}
# more fields...
}
}
This is because Hasura follows SQL by having null not comparable to anything (only _is_null can match values that are set as null in nullable columns).
Therefore, { _eq: null } logically can't match anything, so it's simply optimised away. This:
(where: { user_sets: { set_id: { _eq: $setId } } })
...becomes this:
(where: { user_sets: { set_id: {} } }
...and because {} is trueExp, treated as true, it optimises away to be effectively WHERE 'true'.
I have two indices named "ride" and "audit_log" where audit_log is child of ride. I need to fetch average of timestamp from audit_log table(index) based on some conditions. Conditions span to both parent and child. The query, I am trying to execute is:
curl -XGET 'http://localhost:9200/rides/audit_log/_search' -d
{
"size":0,
"query":{
"has_parent":{
"parent_type":"ride",
"query":{
"match":{
"ride_status":"Ride Completed"
}
}
},
"match":{
"status":"Driver Confirmed"
}
},
"aggs":{
"avg_time":{
"avg":{
"field":"createdAt"
}
}
}
}
here ride_status is from parent table ride.
And, I am getting following error from this api hit:
[has_parent] malformed query, expected [END_OBJECT] but found
[FIELD_NAME]","line":1,"col":107
Try using the term instead of match.
{
"size":0,
"query":{
"has_parent":{
"parent_type":"ride",
"score" : true, <---- add this
"query":{
"term": {
"ride_status":"Ride Completed"
}
}
},
"term": {
"status":"Driver Confirmed"
}
},
"aggs":{
"avg_time":{
"avg":{
"field":"createdAt"
}
}
}
}
I have a basic index with logs
Some logs are visit of user1 to user2
I managed to count the total of visits a user has received, but I don't know how count the total of distinct users a user has received
This is giving me all the logs for a user
{
"post_filter":{
"bool":{
"must":[
{
"term":{
"message":"visit"
}
},
{
"term":{
"ctxt_user2":"733264"
}
}
]
}
},
"query":{
"match_all":{}
}
}
Actually, I'm using FoSElasticaBundle for Symfony2
$filter->addMust((new Term())->setTerm('message', 'visit'));
$filter->addMust((new Term())->setTerm('ctxt_user2', $this->search->getVisit()));
I read some pages in the ES doc with aggregator, but I never managed to get what I want
Convert to SQL, I just need
SELECT COUNT(DISCTING ctxt_user1)
FROM logs
WHERE ctxt_user2 = 733264
EDIT:
Cardinality seams to be what I need.
Now just need to find how use it with FosElasticaBundle
"aggs": {
"yourdistinctcount": {
"cardinality": {
"field": "ctxt_user1"
}
}
}
Try this query ( not tested...):
{
"query" : {
"bool":{
"must":[
{
"term":{
"message":"visit"
}
},
{
"term":{
"ctxt_user2":"733264"
}
}
]
}
},
"aggs": {
"yourdistinctcount": {
"terms": {
"field": "ctxt_user1"
}
}
}
}
The post_filter query cannot be used in your case. As it write on Elastic.co website: The post_filter is applied to the search hits at the very end of a search request, after aggregations have already been calculated.`
HtH,
NOTE: elasticsearch 1.7 and foselastica 3.1 is used!
How do I get only the best matching child in parent/child or nested?
I need to query the whole index (parent and chied fields). The query returns parents, and their children. But I only need parent and best matching child for the query.
I've tried to achieve it with TopChildren, HasChild and so on, but its not working.
This is what my query looks like
{
"query":{
"has_child":{
"type":"variants",
"query":{
"filtered":{
"query":{
"bool":{
"must":[
{
"match":{
"allField":{
"query":"shirt rot",
"operator":"AND",
"minimum_should_match":"80%",
"fuzziness":"0.8",
"analyzer":"custom_search_analyzer"
}
}
}
],
"should":[
{
"match":{
"shortName":{
"query":"shirt rot",
"operator":"AND",
"analyzer":"custom_search_analyzer",
"boost":5
}
}
}
]
}
},
"filter":{
"bool":{
"should":[
{
"terms":{
"customized":[
0
]
}
}
]
}
}
}
},
"max_children":1
}
}
}