Search with fields wildcard not working


(Yuhao Zhang) #1

Hi Currently I am working on elasticsearch 6.2.4
I am not able to perform the wildcard search within specific inner elements of the document like this (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)

this is my document

PUT test/wf/2
{
      "uuid": "51ab247d-033a-4860-97b5-8a58e24a1e0c",
      "writingUuid": {
        "uuid": "943c2055-3cd3-4e6d-b0bb-2d54b1bfec25",
        "nativeUrl": "https://www.todayonline.com/singapore/tighter-security-checkpoints-orchard-road-over-year-end-holiday-period-ica-police",
        "title": "TODAY",
        "content": "Tighter security at checkpoints, Orchard Road over year-end holiday period: ICA, police      SINGAPORE  Expect tighter security checks if you are headed to town or out of the country during the upcoming year-end holiday break the police and immigration authorities said on Wednesday Dec 20.      In separate press releases the Immigrations and Checkpoints Authority IHeaded to town over the long weekend? Take note that checks and security measures will be stepped up in anticipation of bigger crowds during the festive period.",
        "nativeTimeCreated": 1513716000000,
        "kfactsId": "23f48e11-715f-4773-a822-c154a821ac96",
        "platformUuid": {
          "uuid": "caa13e4f-edda-44b5-b124-278e3dbb5430",
          "parentUuid": null,
          "name": "facebook",
          "url": "https://www.facebook.com/",
          "isDeleted": false
        }
      },
      "timeCreated": 1513717846789
  }

I try to do a query on it as the way mentioned in the documentation:

GET /test/_search
{
  "query": {
    "query_string": {
      "query": "tighter security",
      "fields": ["writingUuid.*"]
    }
  }
}

it gives me error below

{
  "error": {
     "root_cause": [
       {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"query_string\" : {\n    \"query\" : \"tighter security\",\n    
\"fields\" : [\n      \"writingUuid.*^1.0\"\n    ],\n    \"type\" : \"best_fields\",\n    \"default_operator\" : 
\"or\",\n    \"max_determinized_states\" : 10000,\n    \"enable_position_increments\" : true,\n    
\"fuzziness\" : \"AUTO\",\n    \"fuzzy_prefix_length\" : 0,\n    \"fuzzy_max_expansions\" : 50,\n    
\"phrase_slop\" : 0,\n    \"escape\" : false,\n    \"auto_generate_synonyms_phrase_query\" : true,\n    
\"fuzzy_transpositions\" : true,\n    \"boost\" : 1.0\n  }\n}",
        "index_uuid": "8E81lxejRdKL9HZyc9ASRg",
        "index": "test"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test",
        "node": "uIDC0NOfSiK3ON0UwY3JCQ",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"query_string\" : {\n    \"query\" : \"tighter security\",\n    
\"fields\" : [\n      \"writingUuid.*^1.0\"\n    ],\n    \"type\" : \"best_fields\",\n    \"default_operator\" : 
\"or\",\n    \"max_determinized_states\" : 10000,\n    \"enable_position_increments\" : true,\n    
\"fuzziness\" : \"AUTO\",\n    \"fuzzy_prefix_length\" : 0,\n    \"fuzzy_max_expansions\" : 50,\n    
\"phrase_slop\" : 0,\n    \"escape\" : false,\n    \"auto_generate_synonyms_phrase_query\" : true,\n    
\"fuzzy_transpositions\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "8E81lxejRdKL9HZyc9ASRg",
          "index": "test",
          "caused_by": {
            "type": "number_format_exception",
            "reason": "For input string: \"tighter security\""
          }
        }
      }
    ]
 },
  "status": 400
}

if I try to query like this:

GET /test/_search
{
  "query": {
    "query_string": {
      "query": "tighter security",
      "fields": ["writingUuid"]
    }
  }
}

this will not return an error but it does not return any hits:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

Unless I specified the field name it will return the result:

GET /test/_search
{
  "query": {
    "query_string": {
      "query": "tighter security",
      "fields": ["writingUuid.content"]
    }
  }
}

Anyone can help me with this issue?


(Yuhao Zhang) #2

Anyone can help me with this issue?


(David Pilato) #3

The problem is that you are searching for a text tighter security in all fields, including nativeTimeCreated which is a number.

Use the lenient option:

GET /test/_search
{
  "query": {
    "query_string": {
      "query": "tighter security",
      "fields": ["writingUuid.*"],
      "lenient": true
    }
  }
}

(Yuhao Zhang) #4

It works, thanks a lot!


(system) #5

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