How to escape colon in query

I am trying to use the atlas search queryString:

      {
        "queryString": {
          "defaultPath": "myPath",
          "query": "11:20:58 OR 11:30"
        }
      }

But the query would fail with the below error:

Caused by: com.mongodb.MongoCommandException: Command failed with error 8 (UnknownError): 'PlanExecutor error during aggregation :: caused by :: Remote error from mongot :: caused by :: Cannot parse '11:20:58 OR 11:30': Encountered " ":" ": "" at line 1, column 5.
Was expecting one of:
    <EOF> 
    <AND> ...
    <OR> ...
    <NOT> ...
    "+" ...
    "-" ...
    <BAREOPER> ...
    "(" ...
    "*" ...
    "^" ...
    <QUOTED> ...
    <TERM> ...
    <FUZZY_SLOP> ...
    <PREFIXTERM> ...
    <WILDTERM> ...
    <REGEXPTERM> ...
    "[" ...
    "{" ...
    <NUMBER> ...

May I ask if you have any suggestions on this? Thank you!
(I tries quote or escape it, but still not working)

Hey @williamwjs,

From the error com.mongodb.MongoCommandException I think you’re using the Java driver. Is this correct? It seems like a syntax issue, however could you please help me with the below details:

  1. Sample document on which the search index has been applied.
  2. The index definition used
  3. Your code that triggered this error
  4. The expected output

Regards,
Satyam

Yes, this is the Java driver.

I am using atlas search, and the index is using the dynamic mapping, and the code is like:

  private static final String QUERY_STRING_CLAUSE = """
      {
        "queryString": {
          "defaultPath": "myPath",
          "query": "11:20:58 OR 11:30"
        }
      }
      """;

      filterOperators.add(SearchOperator.of(Document.parse(QUERY_STRING_CLAUSE)));
      CompoundSearchOperator compoundSearchOperator = SearchOperator.compound().filter(filterOperators);
      Aggregates.search(compoundSearchOperator)

So my expected output here is to find the documents with meeting that OR query.

Hey @williamwjs,

With regard to the question, it’s usually best to work with the actual document example to ensure that all our assumptions are correct. In the absence of an example of an actual document, I’m basing my answer on the code you provided. :sweat_smile: The queryString operator is used for string values and not date-time values. Also, : in queryString denotes <field-to-search>: (<search-values>, which is why it is giving you an error. Could you confirm that you’re searching for two DateTime values and not the actual string "11:20:58" OR "11:30"?

Regards,
Satyam

It is string, not dateTime.
I just tested again, and found making it quoted would work now! So the issue is resolved. Thank you!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.