1

저는 elasticsearch를 처음 사용합니다. 정확한 구문 일치 및 정확한 단어 시퀀스 일치 후에 부분 문자열 일치를 처리하는 near span 기능을 구현하고 싶습니다.탄성 검색 : Span_near 및 하위 문자열 일치

예를 들어

:

  1. 남성 크림
  2. 남자의 주름 개선 크림
  3. 남성의 고급 주름 개선 크림
  4. 여성의 크림
  5. 여성의 주름 개선 크림
  6. :

    문서 나 인덱스에있는

  7. 여성의 장점 나는 "사람의 크림" 검색 경우 에드 주름 개선 크림

, 나는 위의 그림과 같은 순서로 결과를 원한다. 예상 검색 결과 :

  1. 남성 크림 -> 정확한 구문 검색
  2. 남자의 주름 개선 크림 ->slop 1
  3. 남성의 고급 주름 크림 검색어 순서 -> 검색어 순서 slop 2
  4. 정확하게 일치하는 부분에 가까운 여성용 크림 -> 부분 문자열
  5. 여성용 주름 크림 -> 부분 문자열 검색 용어 시퀀스 slop 1
  6. 여성의 고급 주름 개선 크림 -> 문자열 검색어 순서 slop 2

와 내가 span_near으로 처음 3 개 결과를 얻을 수는 slop = 2in_order = truespan_terms을 중첩 한. , span_near 중첩 span_terms을 가지고있다하여이 예를 들어 "남성 크림"OR "남성크림"에, wildcard을 지원하지 않기 때문에
나는 4-6 나머지 그것을 달성 할 수 아니에요. ELASTICSEARCH를 사용하여 달성 할 수있는 방법이 있습니까?

UPDATES
내 인덱스 :

{ 
    "bluray": { 
    "settings": { 
     "index": { 
     "uuid": "4jofvNfuQdqbhfaF2ibyhQ", 
     "number_of_replicas": "1", 
     "number_of_shards": "5", 
     "version": { 
      "created": "1000199" 
     } 
     } 
    } 
    } 
} 

매핑 :

{ 
    "bluray": { 
    "mappings": { 
     "movies": { 
     "properties": { 
      "genre": { 
      "type": "string" 
      } 
     } 
     } 
    } 
    } 
} 

나는 다음과 같은 쿼리를 실행 해요 :

POST /bluray/movies/_search 
{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "span_near": { 
      "clauses": [ 
       { 
       "span_term": { 
        "genre": "women" 
       } 
       }, 
       { 
       "span_term": { 
        "genre": "cream" 
       } 
       } 
      ], 
      "collect_payloads": false, 
      "slop": 12, 
      "in_order": true 
      } 
     }, 
     { 
      "custom_boost_factor": { 
      "query": { 
       "match_phrase": { 
       "genre": "women cream" 
       } 
      }, 
      "boost_factor": 4.1 
      } 
     }, 
     { 
      "match": { 
      "genre": { 
       "query": "women cream", 
       "analyzer": "standard", 
       "minimum_should_match": "99%" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

그것은 결과 다음 날 제공됩니다 :

"took": 3, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 6, 
     "max_score": 0.011612939, 
     "hits": [ 
     { 
      "_index": "bluray", 
      "_type": "movies", 
      "_id": "u9aNkZAoR86uAiW9SX8szQ", 
      "_score": 0.011612939, 
      "_source": { 
       "genre": "men's cream" 
      } 
     }, 
     { 
      "_index": "bluray", 
      "_type": "movies", 
      "_id": "cpTyKrL6TWuJkXvliibVBQ", 
      "_score": 0.009290351, 
      "_source": { 
       "genre": "men's wrinkle cream" 
      } 
     }, 
     { 
      "_index": "bluray", 
      "_type": "movies", 
      "_id": "rn_SFvD4QBO6TJQJNuOh5A", 
      "_score": 0.009290351, 
      "_source": { 
       "genre": "men's advanced wrinkle cream" 
      } 
     }, 
     { 
      "_index": "bluray", 
      "_type": "movies", 
      "_id": "9a31_bRpR2WfWh_4fgsi_g", 
      "_score": 0.004618556, 
      "_source": { 
       "genre": "women's cream" 
      } 
     }, 
     { 
      "_index": "bluray", 
      "_type": "movies", 
      "_id": "q-DoBBl2RsON_qwLRSoh9Q", 
      "_score": 0.0036948444, 
      "_source": { 
       "genre": "women's advanced wrinkle cream" 
      } 
     }, 
     { 
      "_index": "bluray", 
      "_type": "movies", 
      "_id": "TxzCP8B_Q8epXtIcfgEw3Q", 
      "_score": 0.0036948444, 
      "_source": { 
       "genre": "women's wrinkle cream" 
      } 
     } 
     ] 
    } 
} 

어느 것이 정확하지 않습니다.내가 여자를 찾았을 때 왜 남자를 먼저 찾습니까?

참고 : '남성용 크림'을 검색하면 여전히 검색 결과가 좋지만 검색어 순서를 따르지는 않습니다. 로 다음과 같은 출력을 제공

+0

I 시도 인덱스가 여기에서 설명하는 적용 : http://stackoverflow.com/questions/9421358/filename-search-with-elasticsearch하지만 여전히 검색 용어 순서에서 부분 문자열 결과를 반환하지 않습니다. 나는 또한 http://sense.qbox.io/gist/db82c3fca956c8bffae19559b1fe3108c101e851이 제공하는 요지를 사용하여 원하는 결과를 제공하지 않습니다. –

+0

그럼 해결책을 찾았습니까? 나는 같은 문제를 가지고있다. – letalumil

답변

0
POST /bluray/movies/_search 
{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "span_near": { 
      "clauses": [ 
       { 
       "span_term": { 
        "genre": "women's" 
       } 
       }, 
       { 
       "span_term": { 
        "genre": "cream" 
       } 
       } 
      ], 
      "collect_payloads": false, 
      "slop": 12, 
      "in_order": true 
      } 
     },{ 
      "match": { 
      "genre": { 
       "query": "women's cream", 
       "analyzer": "standard", 
       "minimum_should_match": "99%" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

당신의 예상 :

{ 
    "took": 2, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 6, 
    "max_score": 0.7841132, 
    "hits": [ 
     { 
     "_index": "bluray", 
     "_type": "movies", 
     "_id": "4", 
     "_score": 0.7841132, 
     "_source": { 
      "genre": "women's cream" 
     } 
     }, 
     { 
     "_index": "bluray", 
     "_type": "movies", 
     "_id": "5", 
     "_score": 0.56961054, 
     "_source": { 
      "genre": "women's wrinkle cream" 
     } 
     }, 
     { 
     "_index": "bluray", 
     "_type": "movies", 
     "_id": "6", 
     "_score": 0.35892165, 
     "_source": { 
      "genre": "women's advanced wrinkle cream" 
     } 
     }, 
     { 
     "_index": "bluray", 
     "_type": "movies", 
     "_id": "3", 
     "_score": 0.2876821, 
     "_source": { 
      "genre": "men's advanced wrinkle cream" 
     } 
     }, 
     { 
     "_index": "bluray", 
     "_type": "movies", 
     "_id": "1", 
     "_score": 0.25811607, 
     "_source": { 
      "genre": "men's cream" 
     } 
     }, 
     { 
     "_index": "bluray", 
     "_type": "movies", 
     "_id": "2", 
     "_score": 0.11750762, 
     "_source": { 
      "genre": "men's wrinkle cream" 
     } 
     } 
    ] 
    } 
}