14

I'm testing ELK stack for nginx-access logs. It looks good except I have not found a way to search records in Kibana Discovery (v5.3.2) with a path that start with "/test/a". Search works if I remove slashes, but in this case, I get what I don't need - "/ololo/ololo?test=1"

I tried different requests:

path:/\/test\/a/
path:/\\/test\\/a/
path:"/test/a"
path:"\/test\/a"
path:"\\/test\\/a"

but nothing works as I expect.

Records:

[
{
    ...
    "path": "/test/a1"
    ...
},
{
    ...
    "path": "/test/a2"
    ...
},
{
    ...
    "path": "/ololo/ololo?test=1"
    ...
},        
]

Mapping:

"path": {
  "type": "string", 
  "index": "analyzed", 
},

Is there any way to search using slashes as part of pattern?

Update:

These patterns do not work too:

path:/.*\/test\/a.*/
path:/[\/]test[\/]a/

2 Answers 2

12

You need to change the mapping of the path field to not be analyzed, otherwise the slashes will not be indexed.

The mapping should be like this:

"path": {
  "type": "string", 
  "index": "not_analyzed",    <--- change this
},

Note that you need to delete your index and re-create it with the proper mapping in order for this to work.

After that you'll be able to search using the following query path:"/test/a"

10
  • 1
    It does not work. path:"/test/a" returns nothing, instead of records /test/a1 and /test/a2 . This works: path:"/test/a1" or path:"/test/a2", but it's not what I need
    – Alexey
    Jul 8, 2017 at 6:06
  • 1
    Oh sorry I misread your question, I missed the fact that you needed to search for path prefixes. In this case, you should be able to search for path:/test/a* (without the double quotes). Give it a try.
    – Val
    Jul 8, 2017 at 6:22
  • path:/test/a* returns needed records (/test/a1, /test/a2), but also returns a lot of /ololo?test=1. Looks like this pattern return all records that contains word test
    – Alexey
    Jul 8, 2017 at 6:29
  • Let's try something more involved with a regular expression then. Try this: path:/^\/test\/a.*/
    – Val
    Jul 8, 2017 at 6:33
  • path:/^\/test\/a.*/ - No results found.
    – Alexey
    Jul 8, 2017 at 6:38
4

Use this query as example:

{
  "query": {
    "query_string": {
      "fields": [
        "path.keyword"
      ],
      "query": "\\/test\\/a\\/*",
      "analyzer": "keyword",
      "analyze_wildcard": true
    }
  }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.