0

I am indexing the request logs from a java app and the logs contain key method names and time taken. The method names are full method names like

com.example.domain.File[] com.example.service.FolderService.getFiles() throws com.example.Exception

In order to search for a method name or type (like getfiles or File) I believe I need to define a custom analyzer so that it tokenizes the package and method names. Does such an analyzer already exist?

I verified that I can map the field as not_analyzed and use a wildcard for the search. But the docs say that using a wildcard is not very performant and recommends preparing the index correctly.

Looking for other suggestions, ideas as well.

Raylite3
  • 837
  • 2
  • 11
  • 22
  • Did you take a look at [Soot](http://sable.github.io/soot/)? It is a static analyser which can give you what you need and much much more! – Luke Bajada Jun 19 '15 at 19:16

2 Answers2

0

Is the code a part of your project, or something you are just reading in as input?

If it is in your project, you can accomplish this with reflection. The Spring framework is able to do it, take a look at this answer.

Community
  • 1
  • 1
EntangledLoops
  • 1,951
  • 1
  • 23
  • 36
0

I think you don't have all the requirements set, yet. Here's what I'd start with:

PUT /index
{
  "settings": {
    "analysis": {
      "filter": {
        "code": {
          "type": "pattern_capture",
          "preserve_original": 1,
          "patterns": [
            "(\\p{Ll}+|\\p{Lu}\\p{Ll}+|\\p{Lu}+)",
            "(\\d+)"
          ]
        }
      },
      "analyzer": {
        "code": {
          "tokenizer": "pattern",
          "filter": [
            "code",
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "code": {
          "type": "string",
          "analyzer": "code"
        }
      }
    }
  }
}

Test data:

POST /index/test/1
{
  "code": "com.example.domain.File[] com.example.service.FolderService.getFiles() throws com.example.Exception"
}

Query:

GET /index/test/_search
{
  "query": {
    "match": {
      "code": "File"
    }
  }
}
Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
  • Thanks, sounds like the pattern analyzer is what I need (https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pattern-analyzer.html) – Raylite3 Jun 20 '15 at 00:41