Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elastic4s: score stays at 1 with rawQuery

We're using elastic4s for ElasticSearch 2.2.0. A number of queries is stored as JSON on disk and used as rawQuery via the elastic4s driver. The score in the result differs between the query being submitted via command line or the elastic4s driver. The elastic4s driver always returns score of 1 for all results, while the command line execution yields two different scores (for different data types).

The code for elastic4s:

   val searchResult = client.execute {
      search in indexName types(product, company, orga, "User", "Workplace") rawQuery preparedQuery sourceInclude(preparedSourceField:_*) sort {sortDefintions:_*} start start limit limit 
    }.await

Note that I removed anything but rawQuery preparedQuery and it didn't change the score 1. The full query via the command line is quite long:

{
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "query": "${search}",
                        "fields": [
                            "name",
                            "abbreviation",
                            "articleNumberManufacturer",
                            "productLine",
                            "productTitle^10",
                            "productSubtitle",
                            "productDescription",
                            "manufacturerRef.name",
                            "props"
                        ]
                    }
                }
            ],
            "filter": [
                {
                    "or": [
                        {
                            "bool": {
                                "must": [
                                    {
                                        "type": {
                                            "value": "Product"
                                        }
                                    },
                                    {
                                        "term": {
                                            "publishState": "published"
                                        }
                                    }
                                ],
                                "must_not": [
                                    {
                                        "term": {
                                            "productType": "MASTER"
                                        }
                                    },
                                    {
                                        "term": {
                                            "deleted": true
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            ]
        }
    }
}

Note that this is almost preparedQuery but for the replacement of $search with the search query. The elastic search REST client returns a score of 3.075806 for the matches.

like image 550
TeTeT Avatar asked Nov 08 '22 16:11

TeTeT


1 Answers

elastic4s rawQuery will wrap your rawQuery-JSON in another query object.

it's like you would query for

{ "query": { "query": {     
    "bool": {
        "must": [
            {
                "multi_match": {
                    "query": "${search}",
...

just remove your wrapping "query" from you JSON and the response will show varying scores.

Alternatively you can try to use extraSource instead of rawQuery, like described in elastic4s docu. although it didn't work for me at all:

ErrorMessage: value extraSource is not a member of com.sksamuel.elastic4s.SearchDefinition

like image 66
mUnk Avatar answered Nov 15 '22 12:11

mUnk