# Can i use NLP (Question answer) on structured data?

**URL:** <https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 6, 2024, 6:48am UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596 "2024-02-06T06:48:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![9d224d4833094bd482cf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/9d224d4833094bd482cf/32/125623_2.png) [@9d224d4833094bd482cf](https://discuss.elastic.co/u/9d224d4833094bd482cf)\
**Post date:** [February 6, 2024, 6:48am UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/1 "2024-02-06T06:48:26Z")

</div>

We are using Elasticsearch database. We are planning to provide global search with lot of filters. Our data is mostly structured and there are built in relationships. Having many filters on global search can create usability problems.

Is it possible to perform NLP tasks like question/answer or chat bot on structured data? I believe this will help us to get rid of filters and user will be able to search through questions.

---

<div class="post-metadata">

**Author:** ![Tim\_Grein](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_grein/32/121657_2.png) [@Tim\_Grein](https://discuss.elastic.co/u/Tim_Grein)\
**Post date:** [February 6, 2024, 8:59am UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/2 "2024-02-06T08:59:56Z")

</div>

Hi Ashit,

Thank you for your question! There is ongoing development in the (tech-preview) [inference API](https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html), which will probably have more task types added in the future. There's also built-in NLP support, which also supports [question answering models](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-model-ref.html#ml-nlp-model-ref-question-answering). Does this help?

---

<div class="post-metadata">

**Author:** ![9d224d4833094bd482cf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/9d224d4833094bd482cf/32/125623_2.png) [@9d224d4833094bd482cf](https://discuss.elastic.co/u/9d224d4833094bd482cf)\
**Post date:** [February 7, 2024, 5:02am UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/3 "2024-02-07T05:02:49Z")

</div>

Hi Tim,  
Thanks for prompt response.

I was wondering if it is possible to do following:  
User will ask questions like in UI -  
How many students are suffering from covid 19?  
My index doesn't store values in vector form but I would still like to convert above question into proper elastic query and return result to user.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [February 7, 2024, 10:19am UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/4 "2024-02-07T10:19:35Z")

</div>

we have some examples of how you would do this within LangChain.

In this example notebook, you provide a schema for your index and it will transform the question into an BM25 only query.

> <https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/langchain/self-query-retriever-examples/chatbot-with-bm25-only-example.ipynb>

Behind the scenes, LangChain is providing a prompt to transform the query into a structured query, based on the schema and then translating that structured query into a BM25 query. You could do this process manually, without LangChain.

---

<div class="post-metadata">

**Author:** ![9d224d4833094bd482cf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/9d224d4833094bd482cf/32/125623_2.png) [@9d224d4833094bd482cf](https://discuss.elastic.co/u/9d224d4833094bd482cf)\
**Post date:** [February 8, 2024, 11:31am UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/5 "2024-02-08T11:31:53Z")

</div>

Hi Joseph,  
This is really useful. I will try this out.

Could you please elaborate more on your comment - we can translate into structured query manually without LangChain

General Question - Any recommendation on security measures?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [February 9, 2024, 7:27pm UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/6 "2024-02-09T19:27:52Z")

</div>

This article may help give you an understanding of whats happening in self querying [Self-querying | 🦜️🔗 Langchain](https://python.langchain.com/docs/modules/data_connection/retrievers/self_query/)

You could do this yourself without needing LangChain, just means more code to write :). The prompt is:

- providing an instruction to transform the given query into a structured query and giving examples of this.
- The prompt also provides a schema of the fields available, so the LLM knows what attributes it could use for filtering / searching on

This article may help give context also [How to use Elasticsearch to prompt ChatGPT with natural language | Elastic Blog](https://www.elastic.co/blog/elasticsearch-prompt-chatgpt-natural-language)

On security, depends on what security requirements you have. You would need to sanitise the inputs just like you do in any production application.

Joe

---

<div class="post-metadata">

**Author:** ![9d224d4833094bd482cf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/9d224d4833094bd482cf/32/125623_2.png) [@9d224d4833094bd482cf](https://discuss.elastic.co/u/9d224d4833094bd482cf)\
**Post date:** [February 16, 2024, 1:09pm UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/7 "2024-02-16T13:09:01Z")

</div>

Thank you !  
Appreciate your help

---

<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:** [March 15, 2024, 1:09pm UTC](https://discuss.elastic.co/t/can-i-use-nlp-question-answer-on-structured-data/352596/8 "2024-03-15T13:09:16Z")

</div>

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