elasticsearch Elastic/Kibana:在查询搜索中支持复数,elasticsearch,kibana,elasticsearch,Kibana" /> elasticsearch Elastic/Kibana:在查询搜索中支持复数,elasticsearch,kibana,elasticsearch,Kibana" />

elasticsearch Elastic/Kibana:在查询搜索中支持复数

elasticsearch Elastic/Kibana:在查询搜索中支持复数,elasticsearch,kibana,elasticsearch,Kibana,我会简化我的问题。假设我有一个索引,其中包含我用Kibana创建的3个文档: PUT /test/vendors/1 { "type": "doctor", "name": "Phil", "works_in": [ { "place": "Chicago" }, { "place": "New York" } ] } PUT /test/vendors/2 { "type": "law

我会简化我的问题。假设我有一个索引,其中包含我用Kibana创建的3个文档:

PUT /test/vendors/1
{
  "type": "doctor",
  "name": "Phil",
  "works_in": [
      {
        "place": "Chicago"  
      },
      {
        "place": "New York"
      }
    ]
}

PUT /test/vendors/2
{
  "type": "lawyer",
  "name": "John",
  "works_in": [
      {
        "place": "Chicago"  
      },
      {
        "place": "New Jersey"
      }
    ]
}

PUT /test/vendors/3
{
  "type": "doctor",
  "name": "Jill",
  "works_in": [
      {
        "place": "Chicago"  
      }
    ]
}
现在我正在运行搜索:

GET /test/_search
{
  "query": {
    "multi_match" : {
      "query":    "doctor in chicago", 
      "fields": [ "type", "place" ] 
    }
  }
}
我得到了很好的回应:

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "test",
        "_type": "vendors",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "type": "doctor",
          "name": "Phil",
          "works_in": [
            {
              "place": "Chicago"
            },
            {
              "place": "New York"
            }
          ]
        }
      },
      {
        "_index": "test",
        "_type": "vendors",
        "_id": "3",
        "_score": 0.2876821,
        "_source": {
          "type": "doctor",
          "name": "Jill",
          "works_in": [
            {
              "place": "Chicago"
            }
          ]
        }
      }
    ]
  }
}
现在事情开始有问题了

把医生换成医生

由于找不到医生,结果为零。Elastic不知道复数和单数的区别

将查询更改为纽约

但是响应结果集给了我芝加哥的医生和纽约的医生。字段与或匹配

另一个有趣的问题是,如果有人使用DOC、内科医生或卫生专业人员,但指的是医生,会发生什么。有没有规定我可以教Elasticsearch将这些信息输入医生

单独使用elasticsearch是否有任何模式?我不必在自己的应用程序中分析字符串的含义,然后构建一个复杂的精确elasticsearch查询来匹配它


如果有任何指向正确方向的指针,我将不胜感激。我假设字段类型和位置的类型为

要管理单数/复数,您需要将其添加到映射中

您提到的另一项要求是,医生也应等同于医生,您需要利用

下面是您的映射应该是怎样的。注意,我刚刚将analyzer添加到类型中。您可以对映射到其他字段进行类似的更改

映射 根据我共享的链接,它提到上面配置了一个同义词过滤器,其路径是相对于配置位置的analysis/synonym.txt


希望有帮助

工作得很好。我必须删除我的索引,并在将文档放回那里之前先执行此操作,但在那之后,它工作得非常好。有一个问题。。。。没什么可去的了-对不起,我仍在更新我的答案。没有注意到当我发布我的答案时,问题也被更新了。这将需要一段时间,但我会更新你正在寻找的。太棒了。谢谢
GET /test/_search
{
  "query": {
    "multi_match" : {
      "query":    "doctors in chicago", 
      "fields": [ "type", "place" ] 
    }
  }
}
GET /test/_search
{
  "query": {
    "multi_match" : {
      "query":    "doctor in new york", 
      "fields": [ "type", "place" ] 
    }
  }
}
PUT <your_index_name>
{  
   "settings":{  
      "analysis":{  
         "analyzer":{  
            "my_analyzer":{  
               "tokenizer":"standard",
               "filter":[  
                  "lowercase",
                  "my_snow",
                  "my_synonym"
               ]
            }
         },
         "filter":{  
            "my_snow":{  
               "type":"snowball",
               "language":"English"
            },
            "my_synonym":{  
               "type":"synonym",
               "synonyms":[  
                  "docs, physicians, health professionals, doctor"
               ]
            }
         }
      }
   },
   "mappings":{  
      "mydocs":{  
         "properties":{  
            "type":{  
               "type":"text",
               "analyzer":"my_analyzer"
            },
            "place":{  
               "type":"text",
               "analyzer":"my_analyzer"
            }
         }
      }
   }
}
{  
   "type":"synonym",
   "synonyms_path" : "analysis/synonym.txt"
}