2

I'm comparing 2 numeric fields, but it looks like it's not working. The results caintain docs not filtered on the condition. Did I miss something ?

GET crawl-panda-18-06-2018-2-2018/_search

{
  "filtered": {
    "filter": {
      "script": {
        "script": "doc[csv_hit].value > doc[csv_googlebot-desktop].value"
      }
    }
  }
}

Mapping:

    {
  "crawl-panda-18-06-2018-2-2018": {
    "aliases": {},
    "mappings": {
      "items": {
        "properties": {
   (...)
          "csv_googlebot-desktop": {
            "type": "long"
          },
          "csv_hit": {
            "type": "long"
          }
    (...)

Results sample:

"csv_googlebot-desktop": 1,
"csv_hit": 0
Quentin
  • 631
  • 6
  • 16
  • Can you show a sample document that should not be contained in the result set? Also please show your mapping. – Val Jun 25 '18 at 07:10
  • Just did it. Mapping is "number", "searchable" and "aggregatable" for both fields – Quentin Jun 25 '18 at 07:13
  • Added mapping in question – Quentin Jun 25 '18 at 08:00
  • That's not the mapping, that's the index pattern from Kibana. What do you get when running `GET crawl-panda-18-06-2018-2-2018`? – Val Jun 25 '18 at 08:17
  • Ok, sorry. Added the result. – Quentin Jun 25 '18 at 08:29
  • Hi @Val Do you see something wrong ? – Quentin Jun 26 '18 at 07:54
  • In the sample you gave `csv_hit < csv_googlebot-desktop` so your script is correct – Val Jun 26 '18 at 07:55
  • If I invert the "<", the result is the same: "hits": { "total": 66089. => Even If I put mispelled name of field, same total of hits. Is "query" mandatory to make the filter to be functional ? – Quentin Jun 26 '18 at 08:04
  • I see the problem... you have a line between GET and your query, you need to remove it :-) That empty line means "no query" – Val Jun 26 '18 at 08:07
  • Thanks ! It changes everything :) + this type of filter without query doesn't exist anymore... https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-script-filter.html – Quentin Jun 26 '18 at 08:12
  • 1
    Simply replace `filtered` by `bool`. See https://stackoverflow.com/questions/40519806/no-query-registered-for-filtered/40521602#40521602 – Val Jun 26 '18 at 08:16

1 Answers1

0

1st error founds by @Val: Elasticsearch/Kibana don't allow line between GET and the query.

2nd error is that script filter has been replaced by Script Query:

"The script filter has been replaced by the Script Query. It behaves as a query in “query context” and as a filter in “filter context” (see Query DSL)."

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-script-filter.html#query-dsl-script-filter

Works with the following code:

GET index-name/_search
{
    "query": {
        "bool" : {
            "must" : {
                "script" : {
                    "script" : {
                        "source": "doc['field_a'].value > doc['field_b'].value",
                        "lang": "painless"
                     }
                }
            }
        }
    }
}
Quentin
  • 631
  • 6
  • 16