0

I am storing URL in the elastic search and I making the following request to get a result for elastic search:

{
                            "query_string": {
                                "query": "*http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png*",
                                "fields": ["url"],
                                "default_operator": "OR"
                            }
                        }

but elastic search giving Me the following error:

   {
"error": {
    "root_cause": [{
        "type": "query_shard_exception",
        "reason": "Failed to parse query [*http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png*]",
        "index_uuid": "-061pFHDRvmeN_-FWT8ZEg",
        "index": "demo"
    }],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [{
        "shard": 0,
        "index": "demo",
        "node": "je7xKjGTTfWn1rKbuVBbhA",
        "reason": {
            "type": "query_shard_exception",
            "reason": "Failed to parse query [*http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png*]",
            "index_uuid": "-061pFHDRvmeN_-FWT8ZEg",
            "index": "demo",
            "caused_by": {
                "type": "parse_exception",
                "reason": "Cannot parse '*http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png*': Encountered \" \":\" \": \"\" at line 1, column 5.\nWas expecting one of:\n    <EOF> \n    <AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    \"^\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    ",
                "caused_by": {
                    "type": "parse_exception",
                    "reason": "Encountered \" \":\" \": \"\" at line 1, column 5.\nWas expecting one of:\n    <EOF> \n    <AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    \"^\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    "
                }
            }
        }
    }]
},
"status": 400

}

What is the meaning of this error? and How I resolve it? kindly help me here

1 Answer 1

1

You need to explicitly escape the colon from the query as shown below

 "query": "*http\\://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png*"

Modify your search query as

{
  "query": {
    "query_string": {
      "query": "*http\\://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png*",
      "fields": [
        "url"
      ],
      "default_operator": "OR"
    }
  }
}

Update 1:

Index Data:

{
  "url": "http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png"
}

Search Query:

{
  "query": {
    "term": {
      "url.keyword": "http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png"
    }
  }
}

Search Result:

"hits": [
      {
        "_index": "66830399",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.6931471,
        "_source": {
          "url": "http://localhost:8000/v3/assets/dt1234/dt3335/605f068b5e124230eadea17a/my.png"
        }
      }
    ]
Sign up to request clarification or add additional context in comments.

5 Comments

yes, it works fine but it gave me all results that have the same pattern (like localhost:8000/v3/assets/c123/c444/6055555/test.png) is any way in the above query to get only requested URL in the result?
@SurajDalvi please go through the updated part of the answer, and let me know if this resolves your issue ?
Thanks a lot Yes both the answers are right and valid but I want to implement contains query here. if someone passes the full URL or some part of the URL like dt3335/605f068b5e124230eadea17a I want those items that contain this URL. is an option to get it? Please help me here
Can I use query like: { "query_string": { "query": "http\\:\\/\\/localhost\\:8000\\/v3\\/assets\\/c122\\/d122\\/x122\\/my.png", "fields": ["url"], "default_operator": "OR" } }
can you please help me here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.