elasticsearch - Rails Searchkick has_many indexing and searching -


i able search customer_id, name, lastname, , kids id, name, lastname , "birthdate"

the searching id must exact , is. searching names or lastname has misspelling distance 2 , works. want search kid_birthdate match exact (mispelling, distance 0)

so far whenever search birthdate results returned misspelling distance 2. don't know how search exact dates.

rails 5.1.0.rc1

elasticsearch-5.0.3

searchkick-2.2.0

class customer < activerecord::base   include searchable    def search_data     attributes.merge avatar_url: avatar.url, kids: kids   end    has_many :kids   ... end  class kid < activerecord::base     belongs_to :customer      def reindex_customer         customer.reindex async: true     end      ... end        module searchable   extend activesupport::concern    included     search_results_per_page = 10      def self.elastic_search(query, opts = { page: 1 })       # regex accept string contains digits or dates       regexp = /(\d+)|(^(0[1-9]|1\d|2\d|3[01])-(0[1-9]|1[0-2])-(19|20)\d{2}$)/       distance = query.match?(regexp) ? 0 : 2 #this calculate distance misspelling 0 digits , dates , 2 strings       options = { load: false,                   match: :word_middle,                   misspellings: { edit_distance: distance },                   per_page: search_results_per_page,                   page: opts[:page] }       search query, options     end   end end 

my index contains customer data her/his kids data. kids nested under her/his parent customer. how can force searching exact matching dates

for query:

curl http://localhost:9200/customers_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"_all":{"query":"28388","boost":10,"operator":"and","analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"28388","boost":10,"operator":"and","analyzer":"searchkick_search2"}}},{"match":{"_all":{"query":"28388","boost":1,"operator":"and","analyzer":"searchkick_search","fuzziness":0,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"_all":{"query":"28388","boost":1,"operator":"and","analyzer":"searchkick_search2","fuzziness":0,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"size":10,"from":0,"timeout":"11s"}' 

this how index looks:

{   "took": 11,   "timed_out": false,   "_shards": {     "total": 5,     "successful": 5,     "failed": 0   },   "hits": {     "total": 1,     "max_score": 97.29381,     "hits": [       {         "_index": "customers_development_20170913145033808",         "_type": "customer",         "_id": "28388",         "_score": 97.29381,         "_source": {           "id": 28388,           "created_at": "2017-07-10t19:49:43.856z",           "updated_at": "2017-09-13t03:01:51.727z",           "name": "linda",           "lastname": "schott",           "email": "linda.schott@web.de",           "avatar": null,           "phone": null,           "mobile": null,           "erster_kontakt": null,           "memo": null,           "brief_title": null,           "newsletter": null,           "avatar_url": "/no_customer.png",           "kids": [             {               "id": 34229,               "name": "jakob",               "lastname": "schott",               "birthdate": "2013-03-22",               "age": "4,5",               "avatar": {                 "url": "/avatars/kid/34229/jellyfish.png",                 "thumb": {                   "url": "/avatars/kid/34229/thumb_jellyfish.png"                 }               },               "created_at": "2017-07-10t19:50:16.058z",               "updated_at": "2017-09-13t03:02:52.962z",               "customer_id": 28388,               "member": null,               "year_certified": null,               "zahlart": null,               "tn_merge_markiert": null,               "family": null,               "medal": "black",               "score": 30,               "current_level": "swimmys"             },             {               "id": 34228,               "name": "lilith",               "lastname": "schott",               "birthdate": "2013-03-22",               "age": "4,5",               "avatar": {                 "url": "/avatars/kid/34228/penguins.png",                 "thumb": {                   "url": "/avatars/kid/34228/thumb_penguins.png"                 }               },               "created_at": "2017-07-10t19:50:16.058z",               "updated_at": "2017-09-13t03:02:52.962z",               "customer_id": 28388,               "member": null,               "year_certified": null,               "zahlart": null,               "tn_merge_markiert": null,               "family": null,               "medal": "green",               "score": 17,               "current_level": "beginner"             },             {               "id": 27718,               "name": "johanna",               "lastname": "plischke",               "birthdate": "2010-12-29",               "age": "6,8",               "avatar": {                 "url": "/avatars/kid/27718/koala.png",                 "thumb": {                   "url": "/avatars/kid/27718/thumb_koala.png"                 }               },               "created_at": "2017-07-10t19:50:16.034z",               "updated_at": "2017-09-13t04:01:15.261z",               "customer_id": 28388,               "member": null,               "year_certified": null,               "zahlart": null,               "tn_merge_markiert": null,               "family": null,               "medal": "red",               "score": 27,               "current_level": ""             }           ]         }       }     ]   } } 


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -