Elasticsearch: Can it be used to avoid writing your own NLP? (e.g. Re-invent the wheel)

Jas*_*enX 7 elasticsearch

Here's a simplified example of what I'm trying to achieve - I am sure this is a pretty standard thing and I hope someone can point me in the right direction of a pattern, method, way to do this without re-inventing the wheel.

PUT /test/vendors/1
{
  "type": "clinic",
  "name": "ENT of Boston",
  "place": "Boston"  
}

PUT /test/vendors/2
{
  "type": "law firm",
  "name": "Ambulance Chasers Inc.",
  "place": "Boston"  

}
Run Code Online (Sandbox Code Playgroud)

Say I want to support searches like these:

"Ambulance Chasers"
"Law Firm in Boston"
Run Code Online (Sandbox Code Playgroud)

I can run a search like this:

GET /test/_search
{
  "query": {
    "multi_match" : {
      "query":    "Law Firm in Boston", 
      "fields": [ "type", "place", "name" ],
      "type": "most_fields"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

he thing is, this would also get me ENT Of Boston because it has Boston in its name, although that's clearly not what I'm looking for.

I know I can write my own code to analyze the search string before it's submitted to Elasticsearch, and force Boston to be searched only in the place field in documents. I can do that to all fields and issue a super pin-pointer search query for EXACTLY what the user needs. But is there an easier way to handle something like that which I am missing?

I guess what I'm asking is whether there's a way Elasticseaarch can allow me to fine tune and "understand" what I'm looking for, without forcing me to dive deep into Natural Language Processing in my own code and re-invent the wheel.

Kam*_*mal 3

Elasticsearch“搜索”纯粹是基于关键字搜索。

然而,您得到的是一些NLP,例如检索或收集数据、提取所需信息、标记化、停用词删除(所有这些均由分析器完成)、相似性计算(使用 tf-idf 和向量空间模型)。

进一步的 NLP 过程包括提出一个模型、训练该模型、对文本数据进行分类等,我认为 Elasticsearch 没有一个引擎可以做到这一点(有一个名为MLT(更多类似这个)的实现,但我不确定它是如何工作的(还没有读过))。

如果您最终创建了一个 NLP 引擎,您可以使用 elasticsearch 作为 NLP 引擎的源,同样,您不需要实现上面提到的基本阶段。

你可以看看这个博客,很有趣。

无论如何,话虽这么说,但根据您的用例,我提出了以下查询。我知道这不是确切的解决方案,但它会给出您正在寻找的结果。

POST <your_index_name>/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "law",
            "fields": [ "type", "place", "name"],
            "type": "most_fields"
          }
        },
        {
          "multi_match": {
            "query": "firm",
            "fields": [ "type", "place", "name"],
            "type": "most_fields"
          }
        },
        {
          "multi_match": {
            "query": "boston",
            "fields": [ "type", "place", "name"],
            "type": "most_fields"
          }
        }
      ]
    }
  }
} 
Run Code Online (Sandbox Code Playgroud)

我所做的只是使用您发布的查询为每个单词创建一个必须子句。这将确保您最终不会得到您想要的结果。

如果有帮助请告诉我!