1

I have a bunch of documents included in my SOLR index. These documents contain a field that contains JSON data.

When I perform a query with a keyword I want that JSON field to be also searched. Right now it is not working.

QUERY:

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"keyword_to_search",
      "defType":"edismax",
      "qf":"title^300",
      "fl":"field_name:[json]",
      "wt":"json",
      "_":"1551735180672"
    }
  },
  "response":{
    "numFound":0,
    "start":0,
    "docs":[]
  }
}

There is actual documents that contains a JSON field with the data 'keyword_to_search'.

"field_name":"{\"field_key\": \"keyword_to_search\"}",

The field seems to be searchable as I can return the document when querying:

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"{!term f=field_name}keyword_to_search",
      "_":"1551735532524"
    }
  },
  "response":{"numFound":1,"start":0,"docs":[
    {
    ...
    "field_name":"{\"field_key\": \"keyword_to_search\"}",
    }
  ]}
}

How can modify my query to include this?

JSON Structure:

{
  ...
  "field_name": "field_value",
  "columns": [
    ...
    {
        "nested_key": "nested_value_1"
    },
    {
        "nested_key": "nested_value_1"
    },
  ],
}
Rob Fyffe
  • 719
  • 1
  • 8
  • 22

1 Answers1

2

qf=title^300 tells Solr which fields it should search and the weight given to each field.

qf=title^300 json would search both the title field and the json field, and give a hit in title a 300x increase in score compared to a hit it json.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Thanks, this makes the query very slow due to the size of the JSON field. Should I index this as separate documents? If so how do I relate these to the parent, as thats what I want to be returned not the new json docs. – Rob Fyffe Mar 05 '19 at 15:55
  • If there's a specific field in the JSON you want to search, index it as a separate field. How much content are we talking about here? Extracting it as a separate document won't reduce the amount of tokens to be searched, so it'll depend on the definition of `field_name` as well. – MatsLindh Mar 05 '19 at 23:04
  • Its a large JSON object, over 20k characters. I added the structure of the JSON field to the original post. I need to search 3/4 items contained within the array objects. – Rob Fyffe Mar 05 '19 at 23:20
  • I am accepting this answer as it did work. thank you. – Rob Fyffe Mar 07 '19 at 17:43