graphaware / neo4j-to-elasticsearch

GraphAware Framework Module for Integrating Neo4j with Elasticsearch
261 stars 57 forks source link

auto complete field elastic search #130

Closed sofiane01234 closed 6 years ago

sofiane01234 commented 6 years ago

Hi Sir @ikwattro ,

i am implementing the auto complete feature in elastic search with graphaware i need to add the type "completion" in one of index properties ( see code )

 "properties" : {
                "suggest" : {
                    "type" : "completion"
                }
}

is there any solution to do this ? Thanks in advance

ikwattro commented 6 years ago

Hi @sofiane01234 , no we do not support this per se, but there is a trick where you can use a cypher query instead and return a map.

"properties" : {
                "suggest" :  "query('RETURN {\"type\":\"completion\"} AS value')
}
sofiane01234 commented 6 years ago

Hi again @ikwattro , i create the mapping with cypher query that you mentioned but there is a problem. when indexing suggestions it works but it bugs when searching..

Search Request :

`{
    "suggest": {
        "song-suggest" : {
            "prefix" : "nor",
            "completion" : {
                "field" : "suggest"
            }
        }
    }
}`

Request Error :

`{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "no mapping found for field [suggest]"
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "trustiser_test",
                "node": "pbfJ4BRxRLuNSPwvvZLBQw",
                "reason": {
                    "type": "illegal_argument_exception",
                    "reason": "no mapping found for field [suggest]"
                }
            }
        ]
    },
    "status": 400
}`

and when i execute the GET mapping request , i see that the type of "suggest" field has not a normal format of completion field

Get Request :

 "suggest": {
                        "properties": {
                            "input": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "type": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "weight": {
                                "type": "long"
                            }
                        }
                    },

and the normal format of completion field created by postman ( Rest API ) is :

 "suggest": {
                        "type": "completion",
                        "analyzer": "simple",
                        "preserve_separators": true,
                        "preserve_position_increments": true,
                        "max_input_length": 50
                    }

any idea what's the problem ?

sofiane01234 commented 6 years ago

Hello again @ikwattro what you propose to me it does not work.. what I did is to create the mapping of the index directly on elasticsearch with the type completion on the attribute suggest, and then I index the documents from the file mapping.json, in fact when I'am indexing I filled in the "weight" and "input" fields of the suggest attribute manually, as mentioned below :

"properties": {

                "suggest" :  "query('RETURN {input:[\"Medical Doctors\"  , \"Dentists\"], weight : 25 } AS value')" ,

            }

conculsion: it does not work when we create the index via mapping.json, we must first create it directly on elasticsearch, then load the data from mapping.json

Sincerly

ikwattro commented 6 years ago

Hi @sofiane01234 ,

To be clear, our plugin creates an index if it doesn't exist, but will not create the index mapping ( ES ) for you.

Maybe a clarification is needed in the documentation about the mapping word, the mapping.json file you are using in Neo4j is intended only for definiing your replication logic.

The mapping in Elasticsearch should be defined and created by you for your own search needs, this module is only intended at replicating to Elasticsearch and knowledge about how Elasticsearch works is on your side.

Cheers

Christophe