All Apps and Add-ons

dbxlookup with where function()

melonman
Motivator

Hi,

I am looking for a way to embed a fieldvalue to SQL for dbxlookup:

some searches
| eval p1_lon=lon-diff, p1_lat=lat-diff, p2_lon=lon+diff, p2_lat=lat+diff
| eval linestring=p1_lon + " " + p1_lat + ", " + p2_lon + " " + p2_lat
| dbxlookup connection="mysql-splunk" query="
SELECT city, ASTEXT(geom) 
FROM dbconnect.geotable where MBRContains(GeomFromText('LINESTRING(" + linestring + ")'),geom)"
OUTPUT city

, where I want to use linestring field with MBRcontains() function as an input field and get city as output field from the result of SQL.
DB is mysql and connection is OK as tested.

This is working SQL for test..

select city, ASTEXT(geom) from geotable where MBRContains(GeomFromText('LINESTRING(136.71567 35.38456, 136.72877 35.39766)'), geom);

Any comment/hint/thought/example would be appreciated!

Thank you!

mchang_splunk
Splunk Employee
Splunk Employee

Looks like you need to make some changes in dblookup:

| eval p1_lon=lon-diff, p1_lat=lat-diff, p2_lon=lon+diff, p2_lat=lat+diff
| eval linestring=p1_lon + " " + p1_lat + ", " + p2_lon + " " + p2_lat
| dbxlookup connection="mysql-splunk" query="
   SELECT linestring, city FROM dbconnect.geotable 
   where MBRContains(GeomFromText(\""linestring"\")"
         "linestring" AS "linestring" 
         OUTPUT city

melonman
Motivator

Thank you for your comment.
I corrected my mistake in SQL..

I tried the following SQL, but still no success.

| stats count 
| eval lon=136.72222, lat=35.39111, diff=0.00654729
| eval p1_lon=lon-diff, p1_lat=lat-diff, p2_lon=lon+diff, p2_lat=lat+diff
| eval linestring=p1_lon + " " + p1_lat + ", " + p2_lon + " " + p2_lat
| dbxlookup connection="mysql-splunk" query="SELECT city, ASTEXT(geom) FROM dbconnect.geotable where MBRContains(GeomFromText('LINESTRING(\""linestring"\")'),geom)" "linestring" AS "linestring" OUTPUT city

The test SQL in my question should return one city name, but I got the following error..

Error(s) occur when processing chunks in running lookup command. Unknown column 'linestring' in 'field list'.

Does lookup field in Splunk Search should be included to selected field in the SQL?

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...