0

I am trying to use the filters aggregation to get the count of certain items in my index. But it fails with the error - query malformed, no field after start_object

{
  "aggs": {
    "actions": {
      "filters": {
        "filters": {
          "profile_creates": {
            "query": {
              "querystring": "request_method:POST AND path:profile"
            }
          },
          "profile_edits": {
            "query": {
              "querystring": "request_method:PUT AND path:profile"
            }
          }
        }
      }
    }
  }
}

I can't see what's wrong with this query. Can anyone help?

I am using Elasticsearch 1.7.1

This is the exception

[2016-04-18 05:27:09,410][DEBUG][action.search.type       ] [Chance] All shards failed for phase: [query]
org.elasticsearch.transport.RemoteTransportException: [Spitfire][inet[/:9300]][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.search.SearchParseException: [server-logs][7]: from[-1],size[-1]: Parse Failure [Failed to parse source [{
  "aggs": {
    "actions": {
      "filters": {
        "filters": {
          "profilecreate": {
            "query": {
              "querystring": "request_method:POST"
            }
          },
          "profileedit": {
            "query": {
              "querystring": "request_method:PUT"
            }
          }
        }
      }
    }
  }
}]]
      at org.elasticsearch.search.SearchService.parseSource(SearchService.java:747)
      at org.elasticsearch.search.SearchService.createContext(SearchService.java:572)
      at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:544)
      at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:306)
      at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:776)
      at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:767)
      at org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.doRun(MessageChannelHandler.java:279)
      at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:36)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.index.query.QueryParsingException: [server-logs] [_na] query malformed, no field after start_object
      at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:298)
      at org.elasticsearch.index.query.QueryFilterParser.parse(QueryFilterParser.java:47)
      at org.elasticsearch.index.query.QueryParseContext.executeFilterParser(QueryParseContext.java:371)
      at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:352)
      at org.elasticsearch.index.query.IndexQueryParserService.parseInnerFilter(IndexQueryParserService.java:295)
      at org.elasticsearch.search.aggregations.bucket.filters.FiltersParser.parse(FiltersParser.java:63)
      at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:148)
      at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:78)
      at org.elasticsearch.search.aggregations.AggregationParseElement.parse(AggregationParseElement.java:60)
      at org.elasticsearch.search.SearchService.parseSource(SearchService.java:731)
      ... 10 more

1 Answer 1

6

You're missing an underscore in query_string and another keyword query inside the query_string query. You need to write it like this:

{
  "aggs": {
    "actions": {
      "filters": {
        "filters": {
          "profile_creates": {
            "query": {
              "query_string": {"query": "request_method:POST AND path:profile"}
            }
          },
          "profile_edits": {
            "query": {
              "query_string": {"query": "request_method:PUT AND path:profile"}
            }
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

That fixed it. Thanks a million :)

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.