# Help to writing a request

**URL:** <https://discuss.elastic.co/t/help-to-writing-a-request/137152>\
**Category:** Elasticsearch\
**Created:** [June 24, 2018, 3:31pm UTC](https://discuss.elastic.co/t/help-to-writing-a-request/137152 "2018-06-24T15:31:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atef/32/51937_2.png) [@atef](https://discuss.elastic.co/u/atef)\
**Post date:** [June 24, 2018, 3:31pm UTC](https://discuss.elastic.co/t/help-to-writing-a-request/137152/1 "2018-06-24T15:31:08Z")

</div>

Hello  
I have two documents in the elastic search database  
document 1  
{  
section = "baby"  
category = "Clothing"  
subcategory = "shoe"  
}  
document 2  
{  
section = "baby"  
category = "Clothing"  
subcategory = ""  
}

I want to search with elastic search which is the most suitable for research (baby, Clothing)  
I want the result to be document 2 because it is the most suitable

but the problem is both contains baby and clothes

I tried with

GET / \_search  
{  
"query": {  
"bool": {  
"should": [

```
     {"query_string": {
         "query": "baby"
     }},

     {
      
       "query_string": {
         "query": "clothing"
     }}
    
   ]
 
 }

```

}  
}

I got score (document1)\> score (document2) I did not understand

is there anyone can help me write my request to get document2 that resembles the most of the search criteria

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 24, 2018, 3:48pm UTC](https://discuss.elastic.co/t/help-to-writing-a-request/137152/2 "2018-06-24T15:48:40Z")

</div>

If you have 1 shard you should get the same score.  
You can I believe add an exists query to the should clause and add a negative score to it may be?

Or use the function score API.

---

<div class="post-metadata">

**Author:** ![atef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atef/32/51937_2.png) [@atef](https://discuss.elastic.co/u/atef)\
**Post date:** [June 24, 2018, 4:05pm UTC](https://discuss.elastic.co/t/help-to-writing-a-request/137152/3 "2018-06-24T16:05:51Z")

</div>

> [@atef](#):
>
> {  
> section = "baby"  
> category = "Clothing"  
> subcategory = "shoe"  
> }

but for query exists I think I can not check in the query all the words that I do not want because there are other documents like  
document3  
{  
section = "baby"  
category = "Clothing"  
subcategory = "shirt"  
}

the problem is what I can say I want the documents that contain the words baby and / or Clothing only or rather these documents appear with a high score compared to the other

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 24, 2018, 5:01pm UTC](https://discuss.elastic.co/t/help-to-writing-a-request/137152/4 "2018-06-24T17:01:04Z")

</div>

Use a `must` clause instead of `should` then?

BTW please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

---

<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:** [July 22, 2018, 5:01pm UTC](https://discuss.elastic.co/t/help-to-writing-a-request/137152/5 "2018-07-22T17:01:12Z")

</div>

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