# Scripting - custom script to generate span query?

**URL:** <https://discuss.elastic.co/t/scripting-custom-script-to-generate-span-query/281470>\
**Category:** Elasticsearch\
**Created:** [August 15, 2021, 5:08am UTC](https://discuss.elastic.co/t/scripting-custom-script-to-generate-span-query/281470 "2021-08-15T05:08:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![byteandbit](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@byteandbit](https://discuss.elastic.co/u/byteandbit)\
**Post date:** [August 15, 2021, 5:08am UTC](https://discuss.elastic.co/t/scripting-custom-script-to-generate-span-query/281470/1 "2021-08-15T05:08:23Z")

</div>

Our search use case uses Span Queries.

Due to the nature of our data and Span Queries the "query" definition has to be always dynamic as we have to analyse the search text, eg:

"quick brown fox" -\>

```auto

{
	"query": {
		"span_near": {
			"clauses": [
				{
					"span_term": {
						"my_field": "quick"
					}
				},
				{
					"span_term": {
						"my_field": "brown"
					}
				},
				{
					"span_term": {
						"my_field": "fox"
					}
				}
			],
			"slop": 1,
			"in_order": false,
			"boost": 10
		}
		
	},
}

```

Currently we do analyse the query string (split into tokens, asci, lowercase, etc) on the client side, where we build also dynamically the "query".

Is it possible to move such logic to ElasticSearch by using Scripting, or other means?

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 12, 2021, 5:08am UTC](https://discuss.elastic.co/t/scripting-custom-script-to-generate-span-query/281470/2 "2021-09-12T05:08:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
