Help to writing a request


(atef bouabid) #1

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


(David Pilato) #2

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.


(atef bouabid) #3

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


(David Pilato) #4

Use a must clause instead of should then?

BTW please format your code, logs or configuration files using </> icon as explained in this guide 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:

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


(system) #5

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