5

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.

Val
  • 207,596
  • 13
  • 358
  • 360
TeTeT
  • 2,044
  • 20
  • 30
  • When you say result score, is this the per-item score? What does "The elastic search REST client returns a score of 3.075806 for the matches." mean? – James May 13 '16 at 22:45
  • Do you get the exact same results through elastic4s driver and through REST? – Val May 14 '16 at 04:44
  • @James the elastic search REST client means querying elastic search via curl directly. Val the score is different, 1 for elastic4s and 3.075806 for the curl REST query. – TeTeT May 20 '16 at 16:24

1 Answers1

1

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

mUnk
  • 127
  • 5