Elasticsearch-如何仅在搜索“英语”单词时才获得“英语”结果?

时间:2019-11-08 20:46:04

标签: elasticsearch

我的网站有一个带有语言检测器的索引,可以在西班牙语或英语之间切换。我希望能够用英语进行搜索,并且只能获得英语结果。与西班牙语搜索相同。可在以下位置找到处理映射/翻译的代码:https://github.com/Automattic/wpes-lib

我是Elasticsearch的新手,但是已经学习了大约一个月。任何帮助,我们将不胜感激。

我尝试过(下面我正在使用PHP语法):

"must_not" => [
    "match" => [
        "query" => $query,
        "field" => "title.es"       
    ]
],

和:

"must_not" => [
    "match" => [
        "title.es" => [
          "query" => $query
        ]
     ]
],

完整查询如下:

$es_query_args['query']['function_score']['query']['bool'] = [
    "must" => [
      "multi_match" => [
        "query" => $query,
        "type" => "best_fields",
        "fields" => [
          "meta.search_content.value",
          "taxonomy.search_tag.name",
          "title"
        ],
        "fuzziness" => "auto",
        "operator" => "and",
        "tie_breaker" => 0.3
      ],
    ],
     "must_not" => [
       "match" => [
         "query" => $query,
         "fields" => ["title.es"]     
       ]
     ],
    "should" => [
      "multi_match" => [
        "query" => $query,
        "fields" => [
          "title^3", 
          "taxonomy.search_tag.name^3",
          "meta.search_content.value",
        ],
        "fuzziness" => "auto",
        "type" => "phrase",
        "slop" => 5,
      ],
    ],
  ];

没有运气:(

0 个答案:

没有答案