# Querying - filter string Field with CONTAINS

**URL:** <https://community.stardog.com/t/querying-filter-string-field-with-contains/4944>\
**Category:** Support\
**Created:** [May 30, 2024, 9:43am UTC](https://community.stardog.com/t/querying-filter-string-field-with-contains/4944 "2024-05-30T09:43:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AiKuka](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@AiKuka](https://community.stardog.com/u/AiKuka)\
**Post date:** [May 30, 2024, 9:43am UTC](https://community.stardog.com/t/querying-filter-string-field-with-contains/4944/1 "2024-05-30T09:43:27Z")

</div>

Hello, guys!

I am using Stardog to hold some data located in Databricks. I have successfully connected Databricks to Stardog and created a virtual graph. I can query the Graph using both SPARQL in Stardog Studio and GraphQL by forming a request via Python.

I need to figure out how to do this: let's say we have a Class in RDF, in GraphQL it is a Type named 'Type1A'. This class has a property (RDF) / field (GrapQL) named 'Field1A'. Inside this field, string values are saved. And let's say there are multiple instances of this node/object, thus getting us to many string values 'aba', 'bab', 'abc', 'ababa', etc. in the field 'Field1A'. My goal is to return all full 'Field1A' values that contain a substring 'aba', so in our case -\> 'aba', 'ababa' should be returned (sorry for the silly examples, I hope it is understandable).

I have tried to query using GraphQL, and sending this query via Python, requests module:

```auto
"""
    query {
        Type1A(filter: {Field1A: {contains: "aba"}}) {
            nodes {
                Field1A
            }
        }
    }
"""

```

Sadly, to no prevail, as I am getting an error:

```auto
{'errors': [{'extensions': {'classification': 'ValidationError'},
             'locations': [{'column': 28, 'line': 3}],
             'message': 'Validation error of type UnknownArgument: Unknown '
                        "field argument filter @ 'Type1A'"},
            {'extensions': {'classification': 'ValidationError'},
             'locations': [{'column': 13, 'line': 4}],
             'message': 'Validation error of type FieldUndefined: Field '
                        "'nodes' in type 'Type1A' is undefined @ "
                        "'Type1A/nodes'"}]}

```

Obviously, I understand that inside my GraphQL schema I should have defined nodes from this error. However, I cannot neither use arguments to filter fields in my graph using GrapQL nor filter by using 'filter' function. So let's leave it at that, it is a whole another story

I have tried running a SPARQL query in the studio:

```auto
SELECT ?obj_0 ?Field1A
FROM <virtual://my_virtual_graph_name>
WHERE {
  ?obj_0 a <real_class_url> .
  ?obj_0 <real_class_url#Field1A> ?Field1A .
  FILTER(CONTAINS(LCASE(?Field1A), "aba"))
}

```

This returns me exactly what I want, the obj\_0 of the class/type Type1A and all of the values from Field1A that contain "aba".  
If I try to run this query using Stardog CLI tool with this command:

```auto
./stardog query my-db-name "SELECT ?obj_0 ?Field1A FROM <virtual://my_virtual_graph_name> WHERE { ?obj_0 a <real_class_url> . ?obj_0 <real_class_url#Field1A> ?Field1A . FILTER(CONTAINS(LCASE(?Field1A), "aba")) }" --server https://my_stardog_endpoing.stardog.cloud:5820 --username 'username_value' --passwd 'password_value'

```

I always get a message Connection refused, and if I run it with --verbose argument:

```auto
The detailed stack trace for the error is:
com.complexible.stardog.cli.CliException: Connection refused
	at com.complexible.stardog.cli.impl.ConnectionCommand.call(ConnectionCommand.java:87)
	at com.complexible.stardog.cli.CLIBase.execute(CLIBase.java:56)
	at com.complexible.stardog.cli.CLI.main(CLI.java:121)
Caused by: com.complexible.stardog.server.StardogConnectionException: Connection refused
	at com.complexible.stardog.protocols.http.client.Client.toStardogException(Client.java:113)
	at com.complexible.stardog.protocols.http.client.Client.toStardogException(Client.java:101)
	at com.complexible.stardog.protocols.http.client.BaseHttpClient.execute(BaseHttpClient.java:407)
	at com.complexible.stardog.protocols.http.client.HttpClientImpl.select(HttpClientImpl.java:211)
	at com.complexible.stardog.protocols.http.client.HttpConnection._select(HttpConnection.java:253)
	at com.complexible.stardog.api.impl.AbstractConnection.executeSelect(AbstractConnection.java:460)
	at com.complexible.stardog.api.impl.SelectQueryImpl.execute(SelectQueryImpl.java:38)
	at com.complexible.stardog.api.impl.SelectQueryImpl.execute(SelectQueryImpl.java:25)
	at com.complexible.stardog.cli.impl.QueryWithOutput.executeTupleQuery(QueryWithOutput.java:191)
	at com.complexible.stardog.cli.impl.QueryWithOutput.writeOutput(QueryWithOutput.java:103)
	at com.complexible.stardog.cli.impl.Query.execute(Query.java:90)
	at com.complexible.stardog.cli.impl.ConnectionCommand.execute(ConnectionCommand.java:95)
	at com.complexible.stardog.cli.impl.ConnectionCommand.call(ConnectionCommand.java:75)
	... 2 more
Caused by: java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.connect0(Native Method)
	at java.base/sun.nio.ch.Net.connect(Net.java:579)
	at java.base/sun.nio.ch.Net.connect(Net.java:568)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:576)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base/java.net.Socket.connect(Socket.java:666)
	at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
	at com.complexible.stardog.protocols.http.client.BaseHttpClient.execute(BaseHttpClient.java:399)
	... 12 more

```

I have saved the mentioned SPARQL query as a Stored Query in Stardog Studio and when I try to run a command in a terminal using that stored query, I also get a 'Connection refused' message.

Is there anything else that can be done that I could solve my problem - to filter a certain field of a certain type in a contains a substring manner not from Studio, but externally, either using Stardog CLI or, most convenient for me, via Python requests, so either SPARQL or GraphQL?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [November 29, 2024, 4:33am UTC](https://community.stardog.com/t/querying-filter-string-field-with-contains/4944/2 "2024-11-29T04:33:08Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [June 26, 2025, 6:16am UTC](https://community.stardog.com/t/querying-filter-string-field-with-contains/4944/3 "2025-06-26T06:16:08Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 13, 2026, 9:31am UTC](https://community.stardog.com/t/querying-filter-string-field-with-contains/4944/4 "2026-02-13T09:31:33Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [October 20, 2026, 4:50pm UTC](https://community.stardog.com/t/querying-filter-string-field-with-contains/4944/5 "2026-10-20T16:50:15Z")

</div>


