Search in sources :

Example 6 with ElasticsearchQueryString

use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.

the class CommandFactoryTest method combinesQueryStringIfSpecifiedOnMessageListAndQuery.

@Test
void combinesQueryStringIfSpecifiedOnMessageListAndQuery() {
    MessageList ml = MessageList.builder().id("ml-id").query(ElasticsearchQueryString.of("from-messagelist")).build();
    Query q = validQueryBuilderWith(ml).query(ElasticsearchQueryString.of("from-query")).build();
    Search s = searchWithQueries(q);
    ExportMessagesCommand command = buildFrom(s, ml.id());
    ElasticsearchQueryString combined = ElasticsearchQueryString.of("from-query AND from-messagelist");
    assertThat(command.queryString()).isEqualTo(combined);
}
Also used : Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.jupiter.api.Test)

Example 7 with ElasticsearchQueryString

use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.

the class AggregationEventProcessor method groupByQueryString.

// Return the ES query string for the group by fields specified in event; or empty if none specified.
// Search value is escaped and enclosed in quotes.
private ElasticsearchQueryString groupByQueryString(Event event) {
    ElasticsearchQueryString result = ElasticsearchQueryString.empty();
    if (!config.groupBy().isEmpty()) {
        for (String key : event.getGroupByFields().keySet()) {
            String value = event.getGroupByFields().get(key);
            String query = new StringBuilder(key).append(":\"").append(luceneEscape(value)).append("\"").toString();
            result = result.concatenate(ElasticsearchQueryString.of(query));
        }
    }
    return result;
}
Also used : ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)

Aggregations

ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)7 BackendQuery (org.graylog.plugins.views.search.engine.BackendQuery)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Ints (com.google.common.primitives.Ints)1 Assisted (com.google.inject.assistedinject.Assisted)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1