The default_operator=AND not working with multi queries in elasticsearch

I want to search for 2 queries in different fields using elasticsearch like this:

http://localhost:9200/ncar_index/ncar/_search?q=approvetool:مرسوم ملكي AND category:الأنظمة&size=100&sort=date:desc&default_operator=AND

but it act like its OR not AND it the result not exact

can you please help me

Please start using the Query DSL. It seems that over the posts of the last weeks most of your issues come from not properly encoding HTTP parameters and thus probably cutting them off.

You can eliminate a whole problem domain by changing the way you are querying and it is also easier to debug - so I highly recommend you to do so (not for the first time :slight_smile:)

3 Likes

I think there is a "space character" in مرسوم ملكي which probably translates the query to:

approvetool:مرسوم OR ملكي AND category:الأنظمة

My 2 cents

1 Like

You are right next project I will learn how it work with React.js and do so, but this one I need to finish it as fast as possible thank you for your advice and suggest

Yes, the space is intended its like for example a royal letter

and there are other like General letter or minister litter , so it have to both exact

can I solve this?

May be try with approvetool:"مرسوم ملكي" AND category:"الأن"

1 Like

Same problem

I have no idea then.

I'd use the query dsl instead of using the URL to pass the query.

If you don't succeed, could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

1 Like

Okay thank you, I have quick question if possiable if I want to search for like letter but I have others like royal letter and general letter, can I search and get the result of only letter, becasue when I search I get all of them because all have letter term

Please provide a full example.

For example: if I want to search for this

http://localhost:9200/ncar_index/ncar/_search?q=category:letter&size=100&sort=date:desc&default_operator=AND

I will get in the result from three different category :

letter, royal letter, general letter

because they all have

letter

can I search for only exact letter without the other terms

Use a term query instead. Or change the analyzer for this field to be a keyword.

1 Like

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