Elastic-search advanced search query issue

Hi @dadoonet.

please help :pray:

As discussed in the other thread you will need to construct the bool clauses based on what fields the user actually submits.

Hi @Christian_Dahlqvist

you are correct but i have an application that contains 8-search fields

condition here is user some time searching only 3,4,5 fields from current index

when i applied any --bool condition like ---should /must this ---is is not going to fix(as previous DSL ).

so please guide me...how can i implement all 8-fields exact match as user pass the values.

i know ,i am going something alter but this bool is not resolving this use case.

please understand my requirement i want all fields in search query but user may pass only 3,4 fields .


Hi @Christian_Dahlqvist

Please look at my issue and try to help.

You need to create separate queries for each combination of fields.

If this is not the answer I do tho think I understand your question.

Hi @Christian_Dahlqvist .

but how can we implement that as seperate query for each search fields .

Please give some clue ,you are getting my issue in correct way.


You need to build logic into your application that generates the query based on the users input.

Hi @Christian_Dahlqvist.


is there any possible way of design query based on user input please share some link or some idea.

as per current request we have to write 8-different query based on user inputs based on condition but how.


Hi @Christian_Dahlqvist and @dadoonet .

Please help me for this trouble/issue .still i am waiting for some response.

How can we write elastic query based on user input?


You need to provide a script that helps playing with your data as I asked in Elastic-search advanced search query issue.

Then explain what is the exact output you'd like to see.
From that we can have a chance to understand what you want to do and if it's feasible or not.

Hi @dadoonet.

as we discussed previous .

i am using sample query/script below:
<{ "size" : 1000, "query" : { "bool" : { "must" : [ { "bool" : { "must" : [ { "bool" : { "must" : [ { "term" : { "patientname.keyword" : { "value" : "Aadra", "boost" : 1.0 } } }, { "term" : { "sex.keyword" : { "value" : "F", "boost" : 1.0 } } } ] } }, { "term" : { "dob1.keyword" : { "value" : "04/7/1942", "boost" : 1.0 } } } ] } }, { "term" : { "caremanager.keyword" : { "value" : "HEM", "boost" : 1.0 } } } ] } } />

but problem i am facing here :
i have to pass each doc:values if i will not pass value in this query this is fetching null value
but i want to fetch those doc:value what i passed only
this index contains 8-fields/doc and query should be capable to search all 8-fields
but may be some time user can pass only 3,4 doc:value and based on passed value we want exact data.

crying like any thing please help

Very Thanks

I don't understand. And I cannot reproduce anything.

Hi @Christian_Dahlqvist and @dadoonet.

More details :

here is index data contains all(fields/doc):

"patientname":"Aan ra",
"pcp":" ",

but i want to search only below based fields/doc:values and result should be exact match:

"patientname":"Aan ra",

Note : i passed any above value then my query should fetch exact matched data only no other data like or and like operator.

but my query should be able to search only provided doc:value data.

Please continue ...


Hi @dadoonet.

i think you are taking more complex . only problem is that when i use --bool-must-- in my query for search all fields/doc in current .its force to pass fields/doc:'value'.

if i don;t pass the value with search fields/doc:'' " it give nothing/null.

@Christian_Dahlqvist i think you got my problem already please suggest some idea.


Hi @Christian_Dahlqvist and @dadoonet.

this is my final request from forum Team.
please look at this pic and each search fields:

i given GUI view to all forum please try to understand this issue.

case 01 :

i provide patient Name ='ramaya' and gender='M' then fetch all matched ramaya as patientname and M as gender.

case 02:

if i provide patienName ='ramaya' and gender='M' and dob='15/02/1933' then fetch all matched data with given value

case 03:

all search fields will be there in query as shown in GUI. for searching purpose but user can pass only : ----patientname ,gender or dob. not all fields.

case 04:

result should be come only exact matched what user has given on GUI.


As I said before you probably need to write a piece of code that creates the query dynamically based on the fields the user have specified.

If I have understood correctly a template based approach will not work, which seems to be what you are looking for.

Hi @Christian_Dahlqvist.

as you are saying how can this possible in current use case.

for example i have 10- search fields in GUI so we have to write 10*10 means 100-condition here and based on that condition we have to run/execute 100-elastic search query.

correct me if i am wrong here ?

but one more issue how can we handle here multi condition request here with elastic-search.


Hi @Christian_Dahlqvist


You will need to write code that looks at which parameters that have been submitted by the user and based on this created the query DSL with a clause for each provided input. I would not create a template for every possible permutation. I am not sure how I can explain it any clearer than that.

If this is still not clear I give up.

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