Elasticsearch query returning score of 1.0 for all documents?

For the following query

 GET /test/_search

{
  "query": "fire"
}

I get hits with no match all showing a score of 1.0. Any variations of queries I try gives the same results. What's going on here? Results:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 428,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "LbeKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "ancillary space",
          "definition" : """<p class="firstdef-e"><i>Ancillary space</i> means the rooms or spaces in the station used only by the transit agency to house or contain operating, maintenance or support equipment and functions, but does not include booths and kiosks used by the transit agency or
<i>service rooms</i>.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "LreKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "central supervising station",
          "definition" : """<p class="definition-e"><i>Central supervising station</i> means the operations centre where the transit agency controls and co-ordinates the system-wide movement of passengers and vehicles and from which communication is maintained with supervisory and operating personnel of the transit agency and with participating agencies when required.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "L7eKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "crush load",
          "definition" : """<p class="definition-e"><i>Crush load</i> means the total of the seating capacity and the standing capacity of a car where,</p>
<p class="defclause-e">  (a) the seating capacity is the number of seats in a car, and</p>
<p class="defclause-e">  (b) the standing capacity is 0.2 m<sup>2</sup>
per person for the standing area which is measured 300 mm in front of the seats.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "MLeKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "egress capacity",
          "definition" : """<p class="definition-e"><i>Egress capacity</i> means the number of people able to travel from or through a type of egress facility in a specified period of time.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "MbeKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "entraining load",
          "definition" : """<p class="definition-e"><i>Entraining load</i> means the number of passengers boarding the train at a station.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "MreKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "fare-paid area",
          "definition" : """<p class="definition-e"><i>Fare-paid area</i> means that portion of a <i>rapid transit station</i>
to which access is gained by a pass or by paying a fare.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "M7eKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "fare-paid area control",
          "definition" : """<p class="definition-e"><i>Fare-paid area control</i> means the point where passengers enter or leave the <i>fare-paid area</i>.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "NLeKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "link load",
          "definition" : """<p class="definition-e"><i>Link load</i> means the number of passengers on board the train(s) travelling between two stations.</p>""",
          "scope" : "division-b.3.13"
        }
      },
    ....
      }
    ]
  }
}

These are my settings:

{
  "settings": {
    "index": {
      "routing": {
        "allocation": {
          "include": {
            "_tier_preference": "data_content"
          }
        }
      },
      "number_of_shards": "1",
      "provided_name": "ontario-build-code-subsections",
      "creation_date": "1611801847092",
      "number_of_replicas": "1",
      "uuid": "QO8iMmZXTuyO6hgbUqSi-Q",
      "version": {
        "created": "7100299"
      }
    }
  },
  "defaults": {
    "index": {
      "flush_after_merge": "512mb",
      "final_pipeline": "_none",
      "max_inner_result_window": "100",
      "unassigned": {
        "node_left": {
          "delayed_timeout": "1m"
        }
      },
      "max_terms_count": "65536",
      "lifecycle": {
        "name": "",
        "parse_origination_date": "false",
        "indexing_complete": "false",
        "rollover_alias": "",
        "origination_date": "-1"
      },
      "routing_partition_size": "1",
      "force_memory_term_dictionary": "false",
      "max_docvalue_fields_search": "100",
      "merge": {
        "scheduler": {
          "max_thread_count": "1",
          "auto_throttle": "true",
          "max_merge_count": "6"
        },
        "policy": {
          "reclaim_deletes_weight": "2.0",
          "floor_segment": "2mb",
          "max_merge_at_once_explicit": "30",
          "max_merge_at_once": "10",
          "max_merged_segment": "5gb",
          "expunge_deletes_allowed": "10.0",
          "segments_per_tier": "10.0",
          "deletes_pct_allowed": "33.0"
        }
      },
      "max_refresh_listeners": "1000",
      "max_regex_length": "1000",
      "load_fixed_bitset_filters_eagerly": "true",
      "number_of_routing_shards": "1",
      "write": {
        "wait_for_active_shards": "1"
      },
      "verified_before_close": "false",
      "mapping": {
        "coerce": "false",
        "nested_fields": {
          "limit": "50"
        },
        "depth": {
          "limit": "20"
        },
        "field_name_length": {
          "limit": "9223372036854775807"
        },
        "total_fields": {
          "limit": "1000"
        },
        "nested_objects": {
          "limit": "10000"
        },
        "ignore_malformed": "false"
      },
      "source_only": "false",
      "soft_deletes": {
        "enabled": "true",
        "retention": {
          "operations": "0"
        },
        "retention_lease": {
          "period": "12h"
        }
      },
      "max_script_fields": "32",
      "query": {
        "default_field": [
          "*"
        ],
        "parse": {
          "allow_unmapped_fields": "true"
        }
      },
      "format": "0",
      "frozen": "false",
      "sort": {
        "missing": [],
        "mode": [],
        "field": [],
        "order": []
      },
      "priority": "1",
      "codec": "default",
      "max_rescore_window": "10000",
      "max_adjacency_matrix_filters": "100",
      "analyze": {
        "max_token_count": "10000"
      },
      "gc_deletes": "60s",
      "top_metrics_max_size": "10",
      "optimize_auto_generated_id": "true",
      "max_ngram_diff": "1",
      "hidden": "false",
      "translog": {
        "generation_threshold_size": "64mb",
        "flush_threshold_size": "512mb",
        "sync_interval": "5s",
        "retention": {
          "size": "-1",
          "age": "-1"
        },
        "durability": "REQUEST"
      },
      "auto_expand_replicas": "false",
      "mapper": {
        "dynamic": "true"
      },
      "recovery": {
        "type": ""
      },
      "requests": {
        "cache": {
          "enable": "true"
        }
      },
      "data_path": "",
      "highlight": {
        "max_analyzed_offset": "1000000"
      },
      "routing": {
        "rebalance": {
          "enable": "all"
        },
        "allocation": {
          "include": {
            "_tier": ""
          },
          "exclude": {
            "_tier": ""
          },
          "require": {
            "_tier": ""
          },
          "enable": "all",
          "total_shards_per_node": "-1"
        }
      },
      "search": {
        "slowlog": {
          "level": "TRACE",
          "threshold": {
            "fetch": {
              "warn": "-1",
              "trace": "-1",
              "debug": "-1",
              "info": "-1"
            },
            "query": {
              "warn": "-1",
              "trace": "-1",
              "debug": "-1",
              "info": "-1"
            }
          }
        },
        "idle": {
          "after": "30s"
        },
        "throttled": "false"
      },
      "fielddata": {
        "cache": "node"
      },
      "default_pipeline": "_none",
      "max_slices_per_scroll": "1024",
      "shard": {
        "check_on_startup": "false"
      },
      "xpack": {
        "watcher": {
          "template": {
            "version": ""
          }
        },
        "version": "",
        "ccr": {
          "following_index": "false"
        }
      },
      "percolator": {
        "map_unmapped_fields_as_text": "false"
      },
      "allocation": {
        "max_retries": "5",
        "existing_shards_allocator": "gateway_allocator"
      },
      "refresh_interval": "1s",
      "indexing": {
        "slowlog": {
          "reformat": "true",
          "threshold": {
            "index": {
              "warn": "-1",
              "trace": "-1",
              "debug": "-1",
              "info": "-1"
            }
          },
          "source": "1000",
          "level": "TRACE"
        }
      },
      "compound_format": "0.1",
      "blocks": {
        "metadata": "false",
        "read": "false",
        "read_only_allow_delete": "false",
        "read_only": "false",
        "write": "false"
      },
      "max_result_window": "10000",
      "store": {
        "stats_refresh_interval": "10s",
        "type": "",
        "fs": {
          "fs_lock": "native"
        },
        "preload": [],
        "snapshot": {
          "snapshot_name": "",
          "index_uuid": "",
          "cache": {
            "prewarm": {
              "enabled": "true"
            },
            "enabled": "true",
            "excluded_file_types": []
          },
          "uncached_chunk_size": "-1b",
          "index_name": "",
          "repository_name": "",
          "snapshot_uuid": ""
        }
      },
      "queries": {
        "cache": {
          "enabled": "true"
        }
      },
      "warmer": {
        "enabled": "true"
      },
      "max_shingle_diff": "3",
      "query_string": {
        "lenient": "false"
      }
    }
  }
}

and mappings are:

{
  "mappings": {
    "subsection": {
      "properties": {
        "body": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "div": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "header": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "key": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "part": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "rule": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "section": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "subrule": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "subsection": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

Also: when I run the following query on the same index, but with with my python client:

{
  "query": {
      "match": {
          "keyword": "fire"
      }
  }
}

I get sensible results:

'took': 2,
 'timed_out': False,
 '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
 'hits': {'total': {'value': 19, 'relation': 'eq'},
  'max_score': 3.2747047,
  'hits': [{'_index': 'test',
    '_type': 'keyword',
    '_id': 'xbeKSncBVzF2cJ8AZuQC',
    '_score': 3.2747047,
    '_source': {'keyword': 'fire block',
     'definition': '<p class="definition-e"><i>Fire block</i> means a material, component or system that restricts the spread of fire within a concealed space or from a concealed space to an adjacent space.</p>',
     'scope': 'global'}},
   {'_index': 'test',
    '_type': 'keyword',
    '_id': 'xreKSncBVzF2cJ8AZuQC',
    '_score': 3.2747047,
    '_source': {'keyword': 'fire compartment',
     'definition': '<p class="definition-e"><i>Fire compartment</i> means an enclosed space in a <i>building</i>,</p>\n<p class="defclause-e">  (a) that is separated from all other parts of the <i>building</i> by enclosing construction that provides a <i>fire separation</i>, and</p>\n<p class="defclause-e">  (b) that may be required to have a <i>fire-resistance rating</i>.</p>',
     'scope': 'global'}},
   {'_index': 'test',
    '_type': 'keyword',
    '_id': 'x7eKSncBVzF2cJ8AZuQC',
    '_score': 3.2747047,
    '_source': {'keyword': 'fire damper',
     'definition': '<p class="definition-e"><i>Fire damper</i> means a <i>closure </i>that consists of a normally held open damper installed in an air distribution system or in a wall or floor assembly and designed to close automatically in the event of a fire in order to maintain the integrity of the <i>fire separation</i>.</p>',
     'scope': 'global'}},
...

but irrelevant results using the console:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 428,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "LbeKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "ancillary space",
          "definition" : """<p class="firstdef-e"><i>Ancillary space</i> means the rooms or spaces in the station used only by the transit agency to house or contain operating, maintenance or support equipment and functions, but does not include booths and kiosks used by the transit agency or
<i>service rooms</i>.</p>""",
          "scope" : "division-b.3.13"
        }
      },
      {
        "_index" : "test",
        "_type" : "keyword",
        "_id" : "LreKSncBVzF2cJ8AZuQC",
        "_score" : 1.0,
        "_source" : {
          "keyword" : "central supervising station",
          "definition" : """<p class="definition-e"><i>Central supervising station</i> means the operations centre where the transit agency controls and co-ordinates the system-wide movement of passengers and vehicles and from which communication is maintained with supervisory and operating personnel of the transit agency and with participating agencies when required.</p>""",
          "scope" : "division-b.3.13"
        }
      },
...

See that line of space between the two lines you are actually just running

GET /test/_search

Which has no query criteria...

if you actually run

GET /test/_search
{
  "query": "fire"
}

You will get an error like

{
  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "Unknown key for a VALUE_STRING in [query].",
        "line" : 2,
        "col" : 12
      }
    ],
    "type" : "parsing_exception",
    "reason" : "Unknown key for a VALUE_STRING in [query].",
    "line" : 2,
    "col" : 12
  },
  "status" : 400
}
2 Likes

THANK YOU, IT FINALLY WORKS. I never would have guessed that newlines would be an issue.

This works perfectly now:

GET /test/_search
{
  "query": {
      "match": {
          "keyword": "fire"
      }
  }
}
1 Like

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