javascript - Elasticsearch search with multi fields -


how can create body elasticsearch

select * table full_name '%q%' or address '%q%' or description '%q%' order full_name , description , address 

a wildcard query can expensive, if search in several fields. right way using ngram token filter on fields want search part of.

first create index below custom analyzer slice , dice fields searchable tokens:

curl -xput localhost:9200/tests -d '{   "settings": {     "analysis": {       "analyzer": {         "substring_analyzer": {           "tokenizer": "standard",           "filter": ["lowercase", "substring"]         }       },       "filter": {         "substring": {           "type": "ngram",           "min_gram": 1,           "max_gram": 15         }       }     }   },   "mappings": {     "test": {       "properties": {         "full_name": {           "type": "string",           "analyzer": "substring_analyzer"         },         "address": {           "type": "string",           "analyzer": "substring_analyzer"         },         "description": {           "type": "string",           "analyzer": "substring_analyzer"         }       }     }   } }' 

then can index few docs:

curl -xput localhost:9200/tests/test/_bulk -d ' {"index":{"_id": 1}} {"full_name": "doe", "address": "1234 quinn street", "description": "lovely guy"} {"index":{"_id": 2}} {"full_name": "brennan", "address": "4567 main street", "description": "not qualified"} {"index":{"_id": 3}} {"full_name": "quantic", "address": "1234 quinn street", "description": "new friend"} ' 

finally, can search query equivalent sql query above , 3 test documents match:

curl -xput localhost:9200/tests/test/_search -d '{   "query": {     "bool": {       "should": [         {           "match": {             "full_name": "q"           }         },         {           "match": {             "address": "q"           }         },         {           "match": {             "description": "q"           }         }       ]     }   } }' 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -