0

I have a fine output in Elasticsearch with a script.

{
  "fields": [
    "_source"
  ],
  "script_fields": {
    "vermogen": {
      "script_file": "vermogen",
      "params": {
        "ruimtetemperatuur": 18,
        "aanvoertemperatuur": 85,
        "retourtemperatuur": 75
      }
    }
  },
  "query": {
    "bool": {
      "must": [],
      "must_not": [
        {
          "constant_score": {
            "filter": {
              "missing": {
                "field": "article.classification.Warmteafgifte EN 442 20gr C - 75/65"
              }
            }
          }
        }
      ]
    }
  }
}

and this outputs the following:

{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 5099,
    "max_score": 1,
    "hits": [
      {
        "_index": "items",
        "_type": "article",
        "_id": "AU7PHf_Ltb4sVpfKz-ip",
        "_score": 1,
        "_source": {
          "articleCode": "430003",
          "description": "Paneelradiator Henrad Standaard 300-10-800 270W ",
          "searchTerms": "Aangelaste strippen Ja | Aansluitcombi 18 onderzijde links/onderzijde rechts Ja | Aansluitcombi 32 zijkant linksboven/zijkant linksonder Ja | Aansluitcombi 37 zijkant linksboven/zijkant rechtsonder Ja | Aansluitcombi 62 zijkant rechtsboven/zijkant linksonder Ja | Aansluitcombi 67 zijkant rechtsboven/zijkant rechtsonder Ja | Aansluitcombi 81 onderzijde rechts/onderzijde links Ja | Aantal standaard aansluitingen 4 | Diepte 47mm | Diepte 47mm | Diepte 47mm | Draadaansluiting Binnendraad | Draadmaat (inch) 1/2\" | Glansgraad Glanzend | Hoogte 300mm | Hoogte 300mm | Hoogte 300mm | Kleur Wit | Lengte 800mm | Lengte 800mm | Lengte 800mm | Materiaal Staal | Max. werkdruk 10bar | Met aftapaansluiting Ja | Met ontluchtingsaansluiting Ja | N-exponent 1.283' | RAL-nummer 9016' | Standaard kleur Ja | Type 10 | Type 10 | Type 10 | Type 10 | Vlakke voorplaat Geen | Warmteafgifte bepaald door erkend EN 442 laboratorium Ja | Warmteafgifte EN 442 20gr C - 75/65 270W | Warmteafgifte EN 442 20gr C - 75/65 270W | Warmteafgifte EN 442 20gr C - 75/65 270W | Waterinhoud 1.51l | convector Paneelconvector Convectorradiator radiator radiator rad. | 0430003 | EC011022 | StandardB Radiator",
          "grossPrice": 37.24,
          "supplier": "HENRAD ",
          "productClass": "EC011022",
          "classification": {
            "Aangelaste strippen": "Ja",
            "Aansluitcombi 11 onderzijde links/onderzijde links": "Nee",
            "Aansluitcombi 18 onderzijde links/onderzijde rechts": "Ja",
            "Aansluitcombi 32 zijkant linksboven/zijkant linksonder": "Ja",
            "Aansluitcombi 37 zijkant linksboven/zijkant rechtsonder": "Ja",
            "Aansluitcombi 45 bovenzijde links/bovenzijde rechts": "Nee",
            "Aansluitcombi 54 bovenzijde rechts/bovenzijde links": "Nee",
            "Aansluitcombi 62 zijkant rechtsboven/zijkant linksonder": "Ja",
            "Aansluitcombi 67 zijkant rechtsboven/zijkant rechtsonder": "Ja",
            "Aansluitcombi 81 onderzijde rechts/onderzijde links": "Ja",
            "Aansluitcombi 88 onderzijde rechts/onderzijde rechts": "Nee",
            "Aansluitcombi MB middenboven/middenboven": "Nee",
            "Aansluitcombi MO middenonder/middenonder": "Nee",
            "Aantal standaard aansluitingen": "4",
            "Diepte": "47mm",
            "Draadaansluiting": "Binnendraad",
            "Draadmaat (inch)": "1/2\"",
            "Geschikt voor elektrisch element": "Nee",
            "Geschikt voor vochtige ruimte": "Nee",
            "Glansgraad": "Glanzend",
            "Hoogte": "300mm",
            "Kleur": "Wit",
            "Lengte": "800mm",
            "Materiaal": "Staal",
            "Max. werkdruk": "10bar",
            "Met aftapaansluiting": "Ja",
            "Met aftapper": "Nee",
            "Met bevestigingsmateriaal": "Nee",
            "Met blindstoppen": "Nee",
            "Met bovenbekleding": "Nee",
            "Met eenpuntsaansluiting": "Nee",
            "Met elektrisch element": "Nee",
            "Met ontluchter": "Nee",
            "Met ontluchtingsaansluiting": "Ja",
            "Met thermostatisch ventiel geïntegreerd": "Nee",
            "Met wandconsoles": "Nee",
            "Met zijbekleding": "Nee",
            "N-exponent": "1.283'",
            "RAL-nummer": "9016'",
            "Standaard kleur": "Ja",
            "Type": "10",
            "Vlakke voorplaat": "Geen",
            "Warmteafgifte bepaald door erkend EN 442 laboratorium": "Ja",
            "Warmteafgifte EN 442 20gr C - 75/65": "270W",
            "Waterinhoud": "1.51l"
          }
        },
        "fields": {
          "vermogen": [
            355.81461733776723
          ]
        }
      }
    ]
  }
}

So far so good but I'd like to query the output of this script. Is this possible?? Any help is welcome!

2
  • That's not valid JSON due to the " char in the searchTerms field here: Draadmaat (inch) 1/2" Commented Jul 28, 2015 at 11:25
  • i think it showed here as non valid JSON because i copied this text after it was prettyfied. but tnx anyway! Commented Jul 28, 2015 at 15:35

2 Answers 2

1

Why not use script filter , invoke the script that executes the script field code and checks for the condition. More info on how to try it out can be found here.

Sign up to request clarification or add additional context in comments.

2 Comments

i've tried it for god knows how many times but the groovy parser fails. Is there any way to debug these methods?
Oooops... a string is not an integer :-$ ... fiddle fiddle fiddle until it works
0

BTW this is my grooooovy code:

if(!_source.classification.empty && (_source.classification["Warmteafgifte EN 442 20gr C - 75/65"] != null) && (!_source.classification["Warmteafgifte EN 442 20gr C - 75/65"].empty) && (_source.classification["N-exponent"] != null) && (!_source.classification["N-exponent"].empty))
{   
    def wattOrg = (_source.classification["Warmteafgifte EN 442 20gr C - 75/65"].replaceAll("[^\\d.]", "")) as float;   
    def exponent = _source.classification["N-exponent"].replaceAll("[^\\d.]", "") as float;
    def ruimtetemperatuurF = ruimtetemperatuur as float;
    def aanvoertemperatuurF = aanvoertemperatuur as float;
    def retourtemperatuurF = retourtemperatuur as float;

return (((((aanvoertemperatuurF + retourtemperatuurF) / 2F) - ruimtetemperatuurF) / 50F ) ** exponent) * wattOrg;
}
return -1;

//MSSQL: ROUND( POWER( (((Aanvoertemperatuur + Retourtemperatuur) / 2) - Ruimtetemperatuur) / 50, [N-exponent]) * WattOrg , 0)   AS Vermogen 

Does it need some attention? i'm not so well at Java/Groovy code writing...

2 Comments

Turns out neither I am so well with groovy :D
Takes 2 ms longer in the response... Guess it is ok ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.