2

front end is sending async calls to Elastic server. To match the responses, I would like to add the query string in the elastic response json. Does Elastic search have any option to include the query string in the response ?

1

2 Answers 2

2

You can use named queries. You can assign a name to each query which will appear in the result

Query:

{
  "query": {
    "query_string": {
      "query": "this OR thus",
      "_name":"query1"
    }
  }
}

Result:

"hits" : [
      {
        "_index" : "index50",
        "_type" : "_doc",
        "_id" : "VDBsK3IBpnSikKlzkKY3",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "this"
        },
        "matched_queries" : [
          "query1"    ---> name passed in query
        ]
      }
    ]

To search in url:

localhost:9200/_search?pretty&source={"query": {"query_string": {
      "query": "this OR thus", "_name":"query1"} }}
&source_content_type=application/json
Sign up to request clarification or add additional context in comments.

1 Comment

This works from curl. However I need a browser URL. Is it possible ? For example, localshostt/_search?pretty=true&q=cityname:chicago&_name:chicago
0

The documentation https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html doesn’t mention it anyway.

I think that such an option does NOT exist since several types of query exist and for most of them there is more than a query string.

Comments

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.