Search code examples
elasticsearchfull-text-searchsphinx

Full-text searth JSON-string


I have a question: in my DB i have a table, who has a field with JSON-string, like: field "description"

{
solve_what: "Add project problem",
solve_where: "In project CRUD",
shortname: "Add error"
}

How can i full-text search for this string? For example, I need to find all records, who has "project" in description.solve_what. In my sphinx.conf i have

sql_attr_json = description

P.S.Mb i can do this with elasticSearch?


Solution

  • I've just answered a very similar questio here: http://sphinxsearch.com/forum/view.html?id=13861

    Note there is no support for extracting them as FIELDs at this time - so cant 'full-text' search the text within the json elements.

    (To do that would have to use mysql string manipulation functions to create a new column to index as a normal field. Something like:

    SELECT id, SUBSTR(json_column, LOCATE('"tag":"', json_column)+7, LOCATE('"', json_column, LOCATE('"tag":"', json_column)+7)-LOCATE('"tag":"', json_column)-7 ) AS tag, ...

    is messy but should work... )

    The code is untested.