Using variables in searches get different results

TLDR;
I basically have a search that gives result X and I want to create teh same search using a variable but this gives me a different result. Not sure why.

  • What Grafana version and what operating system are you using?
    v7.5.6

  • What are you trying to achieve?
    use a custom vaiable in a search/query

  • How are you trying to achieve it?
    defining the variable in the dashboard settings

  • What happened?
    The full search on its own gives value X when i usee the same search with the variable I get value Y(slightly different to value X) . The difference may be negligible and or rounding error but how do i confirm this?

  • What did you expect to happen?
    I expect to get the same values.

  • Can you copy/paste the configuration(s) that you are having problems with?
    NA

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    NA

  • Did you follow any online instructions? If so, what is the URL?
    No

  • Example search without variable:
    eventType:DeviceRequestResponseEvent
    AND (exists:payload.cattle.name)
    AND (farmId:e9740d29-b56f-43f4-8102-1508708be6cf OR
    farmId:9e89605f-f2b5-4375-8f8a-05b043bc35b5 OR
    farmId:f0470248-3c89-4914-9e58-d3ba49929de8 OR
    farmId:01a46754-2531-4cb4-bfac-bf79417e9e97 OR
    farmId:e4c634d3-f56e-410e-a357-5ae5fe9305f8 OR
    farmId: 2be6f728-c755-4d59-9069-a0f834ae63d0 OR
    farmId:4ef316f1-4628-4457-9468-1a294d1e7769 OR
    farmId:1bf35dbc-ce2b-4a2c-b126-7cd531aa84ad OR
    farmId:067c2d29-40b9-41c9-810e-6ee7fc6c733f OR
    farmId:2cf7b168-d1d7-4097-ba15-ffb722559b60 OR
    farmId:aee7f216-ccad-4a6c-9586-b910a4d99a12 OR
    farmId:27c89d41-e4cf-40a7-8276-5bce52534edd OR
    farmId:caabcc99-4274-46ea-b563-533fa8b31dc1 OR
    farmId:cc7e50e8-ae69-48f8-9e4c-61fbf2e46628)
    AND payload.deviceRequestResponseEvent.payloadType:COMMAND_REQUEST_TYPE

  • Example search with variable:
    eventType:DeviceRequestResponseEvent
    AND (exists:payload.cattle.name)
    ${var_for_all_farms}
    AND payload.deviceRequestResponseEvent.payloadType:COMMAND_REQUEST_TYPE

Hi @hatman,

How different are your x and y outputs? And what is your datasource?


pic shows the difference, note the difference in 2 of the values e.g. 4791 v 4802, possibly negligble but strange that it is happening. any ideas?

panel title LHS:
has the search without variable

panel title RHS:
has the search with the variable

what does your data look like? and your panel JSON?

json panel here

LHS is one without variable
RHS is one with variable

LHS:
"query": "eventType:DeviceRequestResponseEvent\nAND (_exists_:payload.cattle.name)\nAND (farmId:e9740d29-b56f-43f4-8102-1508708be6cf OR \nfarmId:9e89605f-f2b5-4375-8f8a-05b043bc35b5 OR \nfarmId:f0470248-3c89-4914-9e58-d3ba49929de8 OR \nfarmId:01a46754-2531-4cb4-bfac-bf79417e9e97 OR \nfarmId:e4c634d3-f56e-410e-a357-5ae5fe9305f8 OR \nfarmId: 2be6f728-c755-4d59-9069-a0f834ae63d0 OR \nfarmId:4ef316f1-4628-4457-9468-1a294d1e7769 OR \nfarmId:1bf35dbc-ce2b-4a2c-b126-7cd531aa84ad OR \nfarmId:067c2d29-40b9-41c9-810e-6ee7fc6c733f OR \nfarmId:2cf7b168-d1d7-4097-ba15-ffb722559b60 OR \nfarmId:aee7f216-ccad-4a6c-9586-b910a4d99a12 OR \nfarmId:27c89d41-e4cf-40a7-8276-5bce52534edd OR \nfarmId:caabcc99-4274-46ea-b563-533fa8b31dc1 OR \nfarmId:cc7e50e8-ae69-48f8-9e4c-61fbf2e46628)\nAND payload.deviceRequestResponseEvent.payloadType:COMMAND_REQUEST_TYPE",

RHS:
"query": "eventType:DeviceRequestResponseEvent\nAND (_exists_:payload.cattle.name)\n${var_for_all_farms}\nAND payload.deviceRequestResponseEvent.payloadType:COMMAND_REQUEST_TYPE",

variable=

AND (farmId:e9740d29-b56f-43f4-8102-1508708be6cf OR 
farmId:9e89605f-f2b5-4375-8f8a-05b043bc35b5 OR 
farmId:f0470248-3c89-4914-9e58-d3ba49929de8 OR 
farmId:01a46754-2531-4cb4-bfac-bf79417e9e97 OR 
farmId:e4c634d3-f56e-410e-a357-5ae5fe9305f8 OR 
farmId:2be6f728-c755-4d59-9069-a0f834ae63d0 OR 
farmId:4ef316f1-4628-4457-9468-1a294d1e7769 OR 
farmId:1bf35dbc-ce2b-4a2c-b126-7cd531aa84ad OR 
farmId:067c2d29-40b9-41c9-810e-6ee7fc6c733f OR 
farmId:2cf7b168-d1d7-4097-ba15-ffb722559b60 OR 
farmId:aee7f216-ccad-4a6c-9586-b910a4d99a12 OR 
farmId:27c89d41-e4cf-40a7-8276-5bce52534edd OR 
farmId:caabcc99-4274-46ea-b563-533fa8b31dc1 OR 
farmId:cc7e50e8-ae69-48f8-9e4c-61fbf2e46628)

I thought the AND was missing but that is at the start of the variable. But maybe I should remove it from the variable and place it in the search.

what does your data look like?

how do I look at the data? do you mean the csv I can download? tks!