Test query against documents in Elasticsearch without storing them in index

273 Views Asked by At

I have a set of documents that are not stored in any Elasticsearch index (and I don't want to) that I want to test against an Elasticsearch query. Basically I want to see how the Elasticsearch analyser would respond to an arbitrary query against arbitrary documents, without creating indexes.

I've been looking at the Explain API, the Analyze API. Percolate kinda does what I'm looking for but it's completely unnecessary for my case to store the query in an index. The flow with percolate I've been testing is to:

  1. user initiates query
  2. store query in percolate index with randomly generated unique ID
  3. run percolate query with documents: [] array
  4. remove query in percolate index with ID from 2

It's an ad-hoc query so it does not need to be stored, and I'm running into race conditions where the query stored in step 2 only returns results reliably if I put a sleep 1 before running the percolate query.

Basically, the API I'm looking for would look something like this:

GET /_test_query
{
  "query": {
    "simple_query_string": {
       "query": "james blunt",
       "fields": ["title", "content"]
    }
  },
  "documents": [{
     "id": "bbb",
     "title": "James Blunt tweets",
     "content": "That he loves Ibiza"
  }, {
    "id": "aaa",
    "title": "Ed Sheeran tweets",
    "content": "That he loves music"
  }]
}

With a response similar to a regular search query:

{ "hits": { "hits": [{ _id: "bbb"}] } }
// etc

Is this possible in Elasticsearch, or is Percolate the only way?

1

There are 1 best solutions below

0
On

Elasticsearch doesn't have an api like that, but it's a neat idea and it might be worth raising a feature request

index the documents, or use percolate