0

i have a lot of field name in elcsearch , for example :

web_logfield_A, web_logfield_B ,web_logfield_C::abc,
apach_logfield_A, apach_logfield_A

if i want to get these fields value ( web_logfield_A, web_logfield_B ,web_logfield_C::abc )

can i using Regex expression for "field name" to query like

/web_logfield[A-Za-a_]+/

i have try to using .setQuery(QueryBuilders.termQuery("",""), but it's looks like cannot do that ? which method in JAVA API can do that ?

stefansaye
  • 135
  • 1
  • 3
  • 16

4 Answers4

0

Depending on the specific format, you can use this:

web_logfield[^,]+

or even

web_logfield_[^,]+

That is: get everything after web_logfield up to a comma.

See it in action: https://regex101.com/r/dT4nJ2/1

To process the results, then you can create an array of the regex matches.

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598
0

In regex,"+" means that there is one character to match,so your regex can not match "web_logfield_C::abc",I think you can use "web_logfield_[A-Za-Z]+*",which can match one or more characters before "+"

jinjun.zhu
  • 59
  • 4
  • which method in JAVA API can do that ? – stefansaye May 23 '16 at 07:11
  • 1
    For examples on doing regular expressions using Java, please look at this [Java - Regular Expressions tutorial](http://www.tutorialspoint.com/java/java_regular_expressions.htm). – ishmaelMakitla May 23 '16 at 07:16
  • 1
    Welcome to StackOverflow and thank you for helping out members of the community. Your answer provides for some understanding of regular expressions and this is useful - however, since the question specifically wanted to know the Java API/method please consider updating your answer to address this aspect of the question. Also look at some tips on [how to make your answers great](http://stackoverflow.com/help/how-to-answer). – ishmaelMakitla May 23 '16 at 07:20
0

Use Pattern to write regex and use Matcher to match the string.

Pattern p = Pattern.compile("web_logfield[A-Za-a_]+");
Matcher m = p.matcher(str);
while(m.find()){
   String res = m.group();
   System.out.println(res);
}
fedorqui
  • 275,237
  • 103
  • 548
  • 598
zyl
  • 197
  • 1
  • 2
  • 12
0

You should try with a query_string query like this

.setQuery(QueryBuilders.queryStringQuery("xyz").field("web_logfield_*"))

where xyz is what you're trying to match in those fields

Val
  • 207,596
  • 13
  • 358
  • 360