简体   繁体   中英

Elasticsearch, autocomplete search analyzer

I'm using two custom analyzers, autocomplete and a default one:

{
"analysis": {
"analyzer": {
  "autocomplete": {
    "type": "custom",
    "tokenizer": "whitespace",
    "filter": [
      "lowercase",
      "mystopwords",
      "my_stemmer"
    ]
  },
  "default": {
    "type": "custom",
    "tokenizer": "my_tokenizer",
    "filter": [
      "my_delimiter",
      "lowercase"
    ]
  }
},
"tokenizer": {
  "myngram": {
    "type": "ngram",
    "min_gram": 3,
    "max_gram": 30
  },
  "my_tokenizer": {
    "type": "pattern",
    "pattern": "<>"
  }
},
"filter": {
  "mystopwords": {
    "type": "stop",
    "ignore_case": true,
    "_lang_": "french"
  },
  "my_stemmer": {
    "type": "stemmer",
    "name": "french"
  },
  "my_ngram_delimiter": {
    "type": "word_delimiter",
    "preserve_original": false,
    "split_on_numerics": false,
    "catenate_numbers": false,
    "catenate_all": false,
    "split_on_case_change": false,
    "catenate_words": false,
    "generate_word_parts": true,
    "generate_number_parts": false
  },
  "my_delimiter": {
    "type": "word_delimiter",
    "preserve_original": true,
    "split_on_numerics": false,
    "catenate_numbers": false,
    "catenate_all": false,
    "split_on_case_change": false,
    "catenate_words": false,
    "generate_word_parts": false,
    "generate_number_parts": false
  }
}

} }

i'm able to use the autocomplete analyzer without pain with:

curl 'localhost:9200/index/_analyze?pretty=1&analyzer=autocomplete' -d 'polo à manches courtes pour femme'

and the result is :

  {
    "tokens" : [ {
    "token" : "polo",
    "start_offset" : 0,
    "end_offset" : 4,
    "type" : "word",
    "position" : 1
  }, {
    "token" : "à",
    "start_offset" : 5,
    "end_offset" : 6,
    "type" : "word",
    "position" : 2
  }, {
    "token" : "manch",
    "start_offset" : 7,
    "end_offset" : 14,
    "type" : "word",
    "position" : 3
  }, {
    "token" : "court",
    "start_offset" : 15,
    "end_offset" : 22,
    "type" : "word",
    "position" : 4
  }, {
    "token" : "pour",
    "start_offset" : 23,
    "end_offset" : 27,
    "type" : "word",
    "position" : 5
  }, {
    "token" : "femm",
    "start_offset" : 28,
    "end_offset" : 33,
    "type" : "word",
    "position" : 6
  } ]
}

as expected the result is correct , but while performing a query-dsl:

curl -XGET "http://localhost:9200/index/_search?pretty=true" -d'
{
    "size": 2000,
    "fields": ["_id"],
    "query": {
        "filtered": {
            "query": {
        "bool": {
            "must_not":[
                {
                    "match":{"produitStatus":"inactif"}
                }
            ]
        }
    },
            "filter": {
                "and": [{
                   "query":{
                       "nested":{
                           "path":"articleHasAttribut",
                           "query":{
                               "bool": {
                                    "must":[
                                        {
                                            "match":{"articleHasAttribut.recherche":"oui"}
                                        }
                                    ]
                                }
                           }
                       }
                   }     
                }],
                "or": [{
                    "query": {
                        "text": {
                            "libelleArticleCatalogue": { "query":search,"analyzer":"autocomplete"}
                        }
                    }
                }, {
                    "query": {
                        "nested": {
                            "path": "articleHasAttribut",
                            "query": {
                                "text": {
                                    "articleHasAttribut.valeur": { "query":search,"analyzer":"autocomplete"}
                                }
                            }
                        }
                    }
                }, {
                    "query": {
                        "nested": {
                            "path": "articleHasAttribut",
                            "query": {
                                "text": {
                                    "articleHasAttribut.titre": { "query":search,"analyzer":"autocomplete"}
                                }
                            }
                        }
                    }
                }, {
                    "query": {
                        "nested": {
                            "path": "articleHasAttribut",
                            "query": {
                                "text": {
                                    "articleHasAttribut.typeProduit": { "query":search,"analyzer":"autocomplete"}
                                }
                            }
                        }
                    }
                }, {
                    "query": {
                        "text": {
                            "codeArticle": { "query":search,"analyzer":"autocomplete"}
                        }
                    }
                }, {
                    "query": {
                        "text": {
                            "codeCatalogue": { "query":search,"analyzer":"autocomplete"}
                        }
                    }
                }, {
                    "query": {
                        "text": {
                            "attributType": { "query":search,"analyzer":"autocomplete"}
                        }
                    }
                }, {
                    "query": {
                        "text": {
                            "descriptionArticleCatalogue": { "query":search,"analyzer":"autocomplete"}
                        }
                    }
                }]
            }
        }
    }
    ,
    "facets": {
        "Attributs": {
            "terms": {
                "field": "codeArticle"

            }
        }
    }
}'

I didn't get any results:

{
  "took" : 54,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

So the question is why is my autocomplete analyzer not behaving like it should as in the first request without performing any search query-dsl

我在这里http://es.subitolabs.com/#/testr/q3w0yew10q7aatt9创建了一个ES代码段,您可以简化查询还是找出有趣的部分?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM