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 ?
2 Answers
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
1 Comment
marcg
This works from curl. However I need a browser URL. Is it possible ? For example, localshostt/_search?pretty=true&q=cityname:chicago&_name:chicago
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.